[llvm] 900ec97 - [UBSan] Cannot negate smallest negative signed integer

Christopher Tetreault via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 4 10:08:06 PST 2020


Author: Christopher Tetreault
Date: 2020-11-04T10:07:52-08:00
New Revision: 900ec97bbe3254329a77d60201421740b3b2e860

URL: https://github.com/llvm/llvm-project/commit/900ec97bbe3254329a77d60201421740b3b2e860
DIFF: https://github.com/llvm/llvm-project/commit/900ec97bbe3254329a77d60201421740b3b2e860.diff

LOG: [UBSan] Cannot negate smallest negative signed integer

Silence warning Undefined Behavior Sanitzer warning:
runtime error: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D90710

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 35d03f8eb10d..dd5242bbd0cd 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -6239,7 +6239,8 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
       // instead of a CSEL in that case.
       if (TrueVal == ~FalseVal) {
         Opcode = AArch64ISD::CSINV;
-      } else if (TrueVal == -FalseVal) {
+      } else if (FalseVal > std::numeric_limits<int64_t>::min() &&
+                 TrueVal == -FalseVal) {
         Opcode = AArch64ISD::CSNEG;
       } else if (TVal.getValueType() == MVT::i32) {
         // If our operands are only 32-bit wide, make sure we use 32-bit


        


More information about the llvm-commits mailing list