[llvm] r298512 - [ARM] t2_so_imm_neg had a subtle bug in the conversion, and could trigger UB by negating (int)-2147483648. By pure luck, none of the pre-existing tests triggered this; so I'm adding one.
Artyom Skrobov via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 08:09:30 PDT 2017
Author: askrobov
Date: Wed Mar 22 10:09:30 2017
New Revision: 298512
URL: http://llvm.org/viewvc/llvm-project?rev=298512&view=rev
Log:
[ARM] t2_so_imm_neg had a subtle bug in the conversion, and could trigger UB by negating (int)-2147483648. By pure luck, none of the pre-existing tests triggered this; so I'm adding one.
Summary: Thanks to Vitaly Buka for helping catch this.
Reviewers: rengolin, jmolloy, efriedma, vitalybuka
Subscribers: llvm-commits, aemerson
Differential Revision: https://reviews.llvm.org/D31242
Modified:
llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
llvm/trunk/test/CodeGen/Thumb/ispositive.ll
Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=298512&r1=298511&r2=298512&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original)
+++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Wed Mar 22 10:09:30 2017
@@ -111,7 +111,9 @@ def t2_so_imm_notSext : Operand<i32>, Pa
// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
def t2_so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
- int64_t Value = -(int)N->getZExtValue();
+ int64_t Value = N->getZExtValue();
+ if (Value == 1LL<<31) return false; // INT_MIN cannot be negated
+ Value = -(int)Value;
return Value && ARM_AM::getT2SOImmVal(Value) != -1;
}], t2_so_imm_neg_XFORM> {
let ParserMatchClass = t2_so_imm_neg_asmoperand;
Modified: llvm/trunk/test/CodeGen/Thumb/ispositive.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb/ispositive.ll?rev=298512&r1=298511&r2=298512&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb/ispositive.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb/ispositive.ll Wed Mar 22 10:09:30 2017
@@ -9,3 +9,12 @@ entry:
ret i32 %1
}
+define i32 @test2(i32 %X) {
+entry:
+; CHECK-LABEL: test2:
+; CHECK: lsls r1, r1, #31
+; CHECK-NEXT: adds
+ %tmp1 = sub i32 %X, 2147483648
+ ret i32 %tmp1
+}
+
More information about the llvm-commits
mailing list