summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorArtyom Skrobov <Artyom.Skrobov@arm.com>2017-03-22 15:09:30 +0000
committerArtyom Skrobov <Artyom.Skrobov@arm.com>2017-03-22 15:09:30 +0000
commit50a066b3138a2cda4be733fdc51b35aaf631bfce (patch)
tree010772c7498a827956bd7c83ef4df91da6677ae5 /llvm/lib
parent0f3a52b8c9ef8a3298a1c4b9771c72a516fb1075 (diff)
downloadbcm5719-llvm-50a066b3138a2cda4be733fdc51b35aaf631bfce.tar.gz
bcm5719-llvm-50a066b3138a2cda4be733fdc51b35aaf631bfce.zip
[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 llvm-svn: 298512
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/ARM/ARMInstrThumb2.td4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/ARMInstrThumb2.td b/llvm/lib/Target/ARM/ARMInstrThumb2.td
index 557099590c3..45ab65580d4 100644
--- a/llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ b/llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -111,7 +111,9 @@ def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
// 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;
OpenPOWER on IntegriCloud