Fix an array subscript out-of-bounds error

Starting with gcc-11 (verified with gcc-12 as well), an array
out-of-bounds subscript error is reported for accessing the registration
table element at the operation ID index. Validating the index in the
function calling Register/Unregister does not quiet the warning/error
in release builds, so, for gcc-11 and gcc-12, we disable that warning
just for the RegistrationTable class.

Change-Id: I6bc4a02aa072cfa8905ecde5e3960aebf32fc912


[ROCm/roctracer commit: 67ce5fae13]
This commit is contained in:
Laurent Morichetti
2022-09-15 10:33:38 -07:00
rodzic e8cb732660
commit 6dea5c5e3d
2 zmienionych plików z 28 dodań i 0 usunięć
@@ -32,6 +32,19 @@
namespace roctracer::util {
#if __GNUC__ == 11 || __GNUCC__ == 12
// Starting with gcc-11 (verified with gcc-12 as well), an array out-of-bounds subscript error is
// reported for accessing the registration table element at the operation ID index. Validating the
// index in the function calling Register/Unregister does not quiet the warning/error in release
// builds, so, for gcc-11 and gcc-12, we disable that warning just for this class.
#define IGNORE_GCC_ARRAY_BOUNDS_ERROR 1
#endif // __GNUC__ == 11 || __GNUCC__ == 12
#if IGNORE_GCC_ARRAY_BOUNDS_ERROR
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif // IGNORE_GCC_ARRAY_BOUNDS_ERROR
namespace detail {
struct False {
constexpr bool operator()() { return false; }
@@ -78,6 +91,9 @@ template <typename T, uint32_t N, typename IsStopped = detail::False> class Regi
} table_[N]{};
};
#if IGNORE_GCC_ARRAY_BOUNDS_ERROR
#pragma GCC diagnostic pop
#endif // IGNORE_GCC_ARRAY_BOUNDS_ERROR
} // namespace roctracer::util
@@ -489,6 +489,9 @@ static void roctracer_enable_callback_impl(roctracer_domain_t domain, uint32_t o
roctracer_rtapi_callback_t callback, void* user_data) {
std::lock_guard lock(registration_mutex);
if (operation_id >= get_op_end(domain) || callback == nullptr)
throw ApiError(ROCTRACER_STATUS_ERROR_INVALID_ARGUMENT, "invalid argument");
switch (domain) {
case ACTIVITY_DOMAIN_HSA_EVT:
HSA_registration_group.Register(hsa_evt_callback_table, operation_id, callback, user_data);
@@ -538,6 +541,9 @@ ROCTRACER_API roctracer_status_t roctracer_enable_domain_callback(
static void roctracer_disable_callback_impl(roctracer_domain_t domain, uint32_t operation_id) {
std::lock_guard lock(registration_mutex);
if (operation_id >= get_op_end(domain))
throw ApiError(ROCTRACER_STATUS_ERROR_INVALID_ARGUMENT, "invalid argument");
switch (domain) {
case ACTIVITY_DOMAIN_HSA_EVT:
HSA_registration_group.Unregister(hsa_evt_callback_table, operation_id);
@@ -635,6 +641,9 @@ static void roctracer_enable_activity_impl(roctracer_domain_t domain, uint32_t o
if (memory_pool == nullptr)
EXC_RAISING(ROCTRACER_STATUS_ERROR_DEFAULT_POOL_UNDEFINED, "no default pool");
if (op >= get_op_end(domain))
throw ApiError(ROCTRACER_STATUS_ERROR_INVALID_ARGUMENT, "invalid argument");
switch (domain) {
case ACTIVITY_DOMAIN_HSA_EVT:
break;
@@ -701,6 +710,9 @@ ROCTRACER_API roctracer_status_t roctracer_enable_domain_activity(activity_domai
static void roctracer_disable_activity_impl(roctracer_domain_t domain, uint32_t op) {
std::lock_guard lock(registration_mutex);
if (op >= get_op_end(domain))
throw ApiError(ROCTRACER_STATUS_ERROR_INVALID_ARGUMENT, "invalid argument");
switch (domain) {
case ACTIVITY_DOMAIN_HSA_EVT:
break;