Make this compute the correct offset, handling alignment of the element
authorChris Lattner <sabre@nondot.org>
Fri, 12 Oct 2007 17:49:52 +0000 (17:49 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Oct 2007 17:49:52 +0000 (17:49 +0000)
pointer correctly.

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

include/llvm/ADT/StringMap.h

index fecd61ead1b94370f58cf6757c045f14beaad5cc..7f8657e560904147bd1273a912a364a29ac655d6 100644 (file)
@@ -171,8 +171,9 @@ public:
   /// GetStringMapEntryFromValue - Given a value that is known to be embedded
   /// into a StringMapEntry, return the StringMapEntry itself.
   static StringMapEntry &GetStringMapEntryFromValue(ValueTy &V) {
-    return *reinterpret_cast<StringMapEntry*>(reinterpret_cast<char*>(&V) -
-                                              sizeof(StringMapEntryBase));
+    StringMapEntry *EPtr = 0;
+    char *Ptr = reinterpret_cast<char*>(&V) - (intptr_t)&EPtr->Val;
+    return *reinterpret_cast<StringMapEntry*>(Ptr);
   }
   static const StringMapEntry &GetStringMapEntryFromValue(const ValueTy &V) {
     return GetStringMapEntryFromValue(const_cast<ValueTy&>(V));