From 30a05ed11e86642ca378ca1e96908ec9baa7dea9 Mon Sep 17 00:00:00 2001 From: Joseph Greathouse Date: Mon, 29 Jan 2024 08:56:26 -0600 Subject: [PATCH] Fix undefined behavior in definition of hsa_amd_memory_fault_reason_t Currently, the definition of hsa_amd_memory_fault_reason_t tries to set a constant of 0x8000_0000 by using the definition "1 << 31". However, the 1 in this definition is a signed integer by C++ rules. On our architectures, shifting a signed integer by 31 results in signed integer overflow. Signed integer overflow results in undefined behavior. Forcing the 1 to be unsigned avoids this. Change-Id: I860431eeede4eff29598f646abf3c1337b048d71 [ROCm/ROCR-Runtime commit: 1d6691e06b5de1890effc54897a9c74cbc0cff11] --- projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_ext_amd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_ext_amd.h b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_ext_amd.h index 0159238f2b..5117108f28 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -2296,7 +2296,7 @@ typedef enum { // SRAM ECC failure (ie registers, no fault address). HSA_AMD_MEMORY_FAULT_SRAMECC = 1 << 6, // GPU reset following unspecified hang. - HSA_AMD_MEMORY_FAULT_HANG = 1 << 31 + HSA_AMD_MEMORY_FAULT_HANG = 1U << 31 } hsa_amd_memory_fault_reason_t; /**