[llvm] r215143 - [MCJIT] Replace a c-style cast with reinterpret_cast + static_cast.

Lang Hames lhames at gmail.com
Thu Aug 7 13:41:58 PDT 2014


Author: lhames
Date: Thu Aug  7 15:41:57 2014
New Revision: 215143

URL: http://llvm.org/viewvc/llvm-project?rev=215143&view=rev
Log:
[MCJIT] Replace a c-style cast with reinterpret_cast + static_cast.

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.


Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h?rev=215143&r1=215142&r2=215143&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h Thu Aug  7 15:41:57 2014
@@ -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));
   }
 };
 }





More information about the llvm-commits mailing list