Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e42f862

Browse files
authored
[BOLT][AArch64] Avoid UB due to shift of negative value. (#174994)
A build with LLVM_USE_SANITIZER=Undefined showed: bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp:2277:60: runtime error: left shift of negative value -32768 This showed up in bolt/test/AArch64/veneer-lite-mode.s. It is valid for ADRP's operand to be negative, and not valid to shift it like that. To perform this shift reliably, cast the value to unsigned.
1 parent 325869c commit e42f862

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
22742274
!I->getOperand(1).isImm() || I->getOperand(0).getReg() != AArch64::X16)
22752275
return 0;
22762276
TargetHiBits = &*I;
2277-
Addr |= (Address + ((int64_t)I->getOperand(1).getImm() << 12)) &
2277+
Addr |= (Address + ((uint64_t)I->getOperand(1).getImm() << 12)) &
22782278
0xFFFFFFFFFFFFF000ULL;
22792279
Target = Addr;
22802280
return 3;

0 commit comments

Comments
 (0)