This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch branch-1.17.x
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit bb469cbfc00d10ddac7201199c57506e1abf8675
Author: Zoltan Martonka <[email protected]>
AuthorDate: Fri May 3 12:02:44 2024 +0000

    [g++11] Fix DecrementIntCell for g++10 and g++11
    
    There seems to be a compiler bug, that optimizes out the safety check
    for INT_MIN in the DecrementIntCell function. It appears on RHEL 9.2
    with g++ 11.4.1. Only in Release build. For more infoi, see:
    
    
https://stackoverflow.com/questions/78424303/g-optimizes-away-check-for-int-min-in-release-build
    
    The issue seems to be fixed in g++12 and not yet present in g++9.
    
    Solution:
    Slightly change the function to ensure it is compiled correctly.
    This modification should not alter the correct optimized code.
    
    Basically, any change where the compiler cannot perform the two
    optimization steps (in this order) should address the issue:
    
    + if (x == INT_MIN) x = INT_MAX; else x -= 1; ====> x -= 1
    (this is equivalent on the x86 platform).
    + if (x - 1 < x) ====> if (true)
    (this equivalence holds only at the mathematical level).
    
    Change-Id: Ia3cea2849a88c4d7e2587ceb805cd3258652e3c5
    Reviewed-on: http://gerrit.cloudera.org:8080/21396
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Alexey Serbin <[email protected]>
    (cherry picked from commit 1f0c0b0172fb211e74848c87fce983e45280e66d)
    Reviewed-on: http://gerrit.cloudera.org:8080/21982
    Tested-by: Abhishek Chennaka <[email protected]>
---
 src/kudu/common/key_util.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/kudu/common/key_util.cc b/src/kudu/common/key_util.cc
index 290c4b28e..280804f48 100644
--- a/src/kudu/common/key_util.cc
+++ b/src/kudu/common/key_util.cc
@@ -118,7 +118,7 @@ bool DecrementIntCell(void* cell_ptr) {
     // Signed overflow is undefined in C. So, we'll use a branch here
     // instead of counting on undefined behavior.
     if (orig == MathLimits<cpp_type>::kMin) {
-      dec = MathLimits<cpp_type>::kMax;
+      return false;
     } else {
       dec = orig - 1;
     }

Reply via email to