[PATCH] D31242: [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.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 10:51:19 PDT 2017


efriedma added inline comments.


================
Comment at: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td:116
+  if (Value == 1LL<<31) return false; // INT_MIN cannot be negated
+  Value = -(int)Value;
   return Value && ARM_AM::getT2SOImmVal(Value) != -1;
----------------
I think you could simplify this pattern a bit like this:

```
def t2_so_imm_neg : Operand<i32>, ImmLeaf<i32, [{
  return Imm && ARM_AM::getT2SOImmVal(-(uint32_t)Imm) != -1;
}] ...
```


Repository:
  rL LLVM

https://reviews.llvm.org/D31242





More information about the llvm-commits mailing list