This is an archive of the discontinued LLVM Phabricator instance.

[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.
ClosedPublic

Authored by tyomitch on Mar 22 2017, 7:49 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

tyomitch created this revision.Mar 22 2017, 7:49 AM
rengolin added inline comments.Mar 22 2017, 8:11 AM
lib/Target/ARM/ARMInstrThumb2.td
115 ↗(On Diff #92639)

Why not just use INT_MIN?

tyomitch added inline comments.Mar 22 2017, 8:13 AM
lib/Target/ARM/ARMInstrThumb2.td
115 ↗(On Diff #92639)

getZExtValue() would have returned the unsigned value, i.e. (uint64_t)2147483648

rengolin accepted this revision.Mar 22 2017, 8:20 AM

Right. LGTM. Thanks!

This revision is now accepted and ready to land.Mar 22 2017, 8:20 AM
This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.Mar 22 2017, 10:51 AM
llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
116

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;
}] ...
tyomitch marked an inline comment as done.Mar 22 2017, 4:41 PM
vitalybuka added a subscriber: vitalybuka.