[PATCH] Fix undefined behavior (shift of negative value) in RuntimeDyldMachOAArch64::encodeAddend.

Alexey Samsonov vonosmas at gmail.com
Fri Jan 9 15:44:35 PST 2015


Hi lhames, ributzka,

http://reviews.llvm.org/D6908

Files:
  lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h

Index: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
+++ lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
@@ -183,8 +183,8 @@
       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;
     }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6908.17956.patch
Type: text/x-patch
Size: 766 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150109/cced4779/attachment.bin>


More information about the llvm-commits mailing list