[MCJIT] Replace a c-style cast with reinterpret_cast + static_cast.
authorLang Hames <lhames@gmail.com>
Thu, 7 Aug 2014 20:41:57 +0000 (20:41 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 7 Aug 2014 20:41:57 +0000 (20:41 +0000)
C-style casts (and reinterpret_casts) result in implementation defined
values when a pointer is cast to a larger integer type. On some platforms
this was leading to bogus address computations in RuntimeDyldMachOAArch64.

This should fix http://llvm.org/PR20501.

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

lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h

index ced85f3e55a93d9fb3aef0a355d1f036385dbcec..ffdb53a6b1858c09f185f8458a50f2d89a8ca6ef 100644 (file)
@@ -362,9 +362,9 @@ private:
     assert(RE.Size == 2);
     SectionEntry &Section = Sections[RE.SectionID];
     StubMap::const_iterator i = Stubs.find(Value);
-    uint8_t *Addr;
+    uintptr_t Addr;
     if (i != Stubs.end())
-      Addr = Section.Address + i->second;
+      Addr = reinterpret_cast<uintptr_t>(Section.Address) + i->second;
     else {
       // FIXME: There must be a better way to do this then to check and fix the
       // alignment every time!!!
@@ -385,11 +385,11 @@ private:
       else
         addRelocationForSection(GOTRE, Value.SectionID);
       Section.StubOffset = StubOffset + getMaxStubSize();
-      Addr = (uint8_t *)StubAddress;
+      Addr = StubAddress;
     }
     RelocationEntry TargetRE(RE.SectionID, RE.Offset, RE.RelType, /*Addend=*/0,
                              RE.IsPCRel, RE.Size);
-    resolveRelocation(TargetRE, (uint64_t)Addr);
+    resolveRelocation(TargetRE, static_cast<uint64_t>(Addr));
   }
 };
 }