Fix undefined behavior (shift of negative value) in RuntimeDyldMachOAArch64::encodeAd...
authorAlexey Samsonov <vonosmas@gmail.com>
Sat, 10 Jan 2015 00:46:38 +0000 (00:46 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Sat, 10 Jan 2015 00:46:38 +0000 (00:46 +0000)
Test Plan: regression test suite with/without UBSan.

Reviewers: lhames, ributzka

Subscribers: aemerson, llvm-commits

Differential Revision: http://reviews.llvm.org/D6908

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225568 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h

index 274c5523011315be182109dc767c0ecf07d9c316..196fa62a0a0781d5fbe0e54ce4a31d8ff77cd829 100644 (file)
@@ -183,8 +183,8 @@ public:
       assert(isInt<33>(Addend) && "Invalid page reloc value.");
 
       // Encode the addend into the instruction.
-      uint32_t ImmLoValue = (uint32_t)(Addend << 17) & 0x60000000;
-      uint32_t ImmHiValue = (uint32_t)(Addend >> 9) & 0x00FFFFE0;
+      uint32_t ImmLoValue = ((uint64_t)Addend << 17) & 0x60000000;
+      uint32_t ImmHiValue = ((uint64_t)Addend >> 9) & 0x00FFFFE0;
       *p = (*p & 0x9F00001F) | ImmHiValue | ImmLoValue;
       break;
     }