From 4bc8dbd029c433f060f9f0742c9b1c332e2e4b3a Mon Sep 17 00:00:00 2001 From: Giovanni LB Date: Wed, 28 Feb 2024 23:56:14 -0300 Subject: [PATCH] SWDEV-448279: Workaround for UB24 compiler errors Change-Id: I01e880502edac8e8b941d199e08bc8f1eded0a89 --- src/roctracer/registration_table.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/roctracer/registration_table.h b/src/roctracer/registration_table.h index f9f6efd478..7ead61aed4 100644 --- a/src/roctracer/registration_table.h +++ b/src/roctracer/registration_table.h @@ -54,9 +54,15 @@ struct False { // Generic callbacks table template class RegistrationTable { public: + struct table_element_t { + std::atomic enabled{false}; + mutable std::shared_mutex mutex; + T data; + }; + template void Register(uint32_t operation_id, Args... args) { assert(operation_id < N && "operation_id is out of range"); - auto& entry = table_[operation_id]; + table_element_t& entry = table_.at(operation_id); std::unique_lock lock(entry.mutex); if (!entry.enabled.exchange(true, std::memory_order_relaxed)) registered_count_.fetch_add(1, std::memory_order_relaxed); @@ -65,7 +71,7 @@ template class Regi void Unregister(uint32_t operation_id) { assert(operation_id < N && "id is out of range"); - auto& entry = table_[operation_id]; + table_element_t& entry = table_.at(operation_id); std::unique_lock lock(entry.mutex); if (entry.enabled.exchange(false, std::memory_order_relaxed)) registered_count_.fetch_sub(1, std::memory_order_relaxed); @@ -73,7 +79,7 @@ template class Regi std::optional Get(uint32_t operation_id) const { assert(operation_id < N && "id is out of range"); - auto& entry = table_[operation_id]; + const table_element_t& entry = table_.at(operation_id); if (!entry.enabled.load(std::memory_order_relaxed) || IsStopped{}()) return std::nullopt; std::shared_lock lock(entry.mutex); return entry.enabled.load(std::memory_order_relaxed) ? std::make_optional(entry.data) @@ -84,11 +90,7 @@ template class Regi private: std::atomic registered_count_{0}; - struct { - std::atomic enabled{false}; - mutable std::shared_mutex mutex; - T data; - } table_[N]{}; + std::array table_{}; }; #if IGNORE_GCC_ARRAY_BOUNDS_ERROR