From bf22d10ceb03ebe65d0ebf59f39ff0cf74e2cb05 Mon Sep 17 00:00:00 2001 From: Sreekant Somasekharan Date: Mon, 5 Jun 2023 18:24:17 -0400 Subject: [PATCH] rocrtst: Fix RoundToPowerOf2 function Compiler behavior is undefined if the right operand is negative, or greater than or equal to the width of the promoted left operand. For release builds with address sanitizer enabled, this compiler optimization behavior leads to unsupported queue size value since current method shifts till 128 bits on a 64 bit value. Change-Id: Iddcc15b43d2331bc8bf5fc3aa4725f76844655ec Signed-off-by: Sreekant Somasekharan [ROCm/ROCR-Runtime commit: ea2f832a439b30184288e9a869a1a26058d95e2b] --- .../rocr-runtime/rocrtst/common/helper_funcs.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) mode change 100755 => 100644 projects/rocr-runtime/rocrtst/common/helper_funcs.cc diff --git a/projects/rocr-runtime/rocrtst/common/helper_funcs.cc b/projects/rocr-runtime/rocrtst/common/helper_funcs.cc old mode 100755 new mode 100644 index f145ffe49e..5b421029d3 --- a/projects/rocr-runtime/rocrtst/common/helper_funcs.cc +++ b/projects/rocr-runtime/rocrtst/common/helper_funcs.cc @@ -103,16 +103,15 @@ int FillRandom(T* arrayPtr, } uint64_t RoundToPowerOf2(uint64_t val) { - int bytes = sizeof(uint64_t); - val--; - - for (int i = 0; i < bytes; i++) { - val |= val >> (1 << i); - } + /* + * Shift with amount larger than the bit width can result in + * undefined behavior by compiler for release builds. + * Shift till 32 bit only which is less than bit width of val. + */ + for (int i = 1; i <= 32; i *= 2) val |= val >> i; val++; - return val; }