[BOLT][NFC] Fix UB due to left shift of negative value
authorJob Noorman <jnoorman@igalia.com>
Thu, 13 Apr 2023 12:29:18 +0000 (14:29 +0200)
committerJob Noorman <jnoorman@igalia.com>
Thu, 13 Apr 2023 12:29:19 +0000 (14:29 +0200)
The following test fails when enabling UBSan due to a left shift of a
negative value:

> runtime error: left shift of negative value -2

  BOLT :: AArch64/ext-island-ref.s

This patch fixes this by using a multiplication instead of a shift.

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D148218

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

index ec9f78d..90016ed 100644 (file)
@@ -265,7 +265,7 @@ public:
         return true;
       }
 
-      DispImm = Inst.getOperand(I).getImm() << 2;
+      DispImm = Inst.getOperand(I).getImm() * 4;
       return true;
     }
     return false;