Skip to content

Commit d8900f6

Browse files
committed
[ARM] Fix abs overflow when encoding instructions like strb r1, [r0], #-0
Tested by llvm/test/MC/ARM/basic-thumb2-instructions.s. Caught by newer -fsanitize=signed-integer-overflow (D156821).
1 parent 6a0e536 commit d8900f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,9 @@ getT2AddrModeImm8OffsetOpValue(const MCInst &MI, unsigned OpNum,
16611661

16621662
// FIXME: Needs fixup support.
16631663
unsigned Value = 0;
1664-
int32_t tmp = (int32_t)MO1.getImm();
1665-
if (tmp < 0)
1666-
tmp = abs(tmp);
1664+
auto tmp = static_cast<uint32_t>(MO1.getImm());
1665+
if (static_cast<int32_t>(tmp) < 0)
1666+
tmp = -tmp;
16671667
else
16681668
Value |= 256; // Set the ADD bit
16691669
Value |= tmp & 255;

0 commit comments

Comments
 (0)