Updated backpatching during object deserialization to support "smart"
authorTed Kremenek <kremenek@apple.com>
Thu, 25 Oct 2007 23:40:35 +0000 (23:40 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 25 Oct 2007 23:40:35 +0000 (23:40 +0000)
pointers that employ unused bits in a pointer to store extra data.

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

include/llvm/Bitcode/Deserialize.h
lib/Bitcode/Reader/Deserialize.cpp

index 164c70a9af68992e83214c758cd937e26a349170..6eaba51ecc30477c06a866aa70711d7acf5f4d76 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/DataTypes.h"
 #include <vector>
 
 namespace llvm {
@@ -40,8 +41,11 @@ class Deserializer {
   
   struct BPatchNode {
     BPatchNode* const Next;
-    void*& PtrRef;    
-    BPatchNode(BPatchNode* n, void*& pref) : Next(n), PtrRef(pref) {}
+    uintptr_t& PtrRef;
+    BPatchNode(BPatchNode* n, void*& pref) 
+      : Next(n), PtrRef(reinterpret_cast<uintptr_t&>(pref)) {
+        PtrRef = 0;
+      }
   };
   
   struct BPatchEntry {
index 3e16027839c5d46d1bbb85466631690357fc87b7..66df46ea23e32e6a17194d767b1d5c55d655a591 100644 (file)
@@ -126,7 +126,9 @@ void Deserializer::BackpatchPointers() {
     assert (Entry.Ptr && "No pointer found for backpatch.");
     
     for (BPatchNode* N = Entry.Head; N != NULL; N = N->Next)
-      N->PtrRef = Entry.Ptr;
+      // Bitwise-OR in the pointer to support "smart" pointers that use
+      // unused bits to store extra data.
+      N->PtrRef |= reinterpret_cast<uintptr_t>(Entry.Ptr);
     
     Entry.Head = NULL;
   }