Skip to content

Commit 0c756c5

Browse files
MaskRaytru
authored andcommitted
[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). (cherry picked from commit d8900f6)
1 parent 3444abf commit 0c756c5

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
@@ -1672,9 +1672,9 @@ getT2AddrModeImm8OffsetOpValue(const MCInst &MI, unsigned OpNum,
16721672

16731673
// FIXME: Needs fixup support.
16741674
unsigned Value = 0;
1675-
int32_t tmp = (int32_t)MO1.getImm();
1676-
if (tmp < 0)
1677-
tmp = abs(tmp);
1675+
auto tmp = static_cast<uint32_t>(MO1.getImm());
1676+
if (static_cast<int32_t>(tmp) < 0)
1677+
tmp = -tmp;
16781678
else
16791679
Value |= 256; // Set the ADD bit
16801680
Value |= tmp & 255;

0 commit comments

Comments
 (0)