Augmented ReadPtr and ReadOwnedPtr to control whether or not a pointer is allowed...
authorTed Kremenek <kremenek@apple.com>
Tue, 6 Nov 2007 22:21:14 +0000 (22:21 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 6 Nov 2007 22:21:14 +0000 (22:21 +0000)
or can be registered with the deserializer to backpatch other pointers.

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

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

index 283e6035c795c2fea50bb01dc71b7b47efb22d5e..9fdbc8cd9656aa66e35bdaf897772707d01b621c 100644 (file)
@@ -114,33 +114,36 @@ public:
   void ReadCStr(std::vector<char>& buff, bool isNullTerm=false);
 
   template <typename T>
-  inline T* ReadOwnedPtr() {    
+  inline T* ReadOwnedPtr(bool AutoRegister = true) {
     unsigned PtrId = ReadInt();
 
     if (PtrId == 0)
       return NULL;
     
     T* x = SerializeTrait<T>::Materialize(*this);
-    RegisterPtr(PtrId,x);
+    
+    if (AutoRegister)
+      RegisterPtr(PtrId,x);
+    
     return x;
   }
   
   template <typename T>
-  inline void ReadOwnedPtr(T*& Ptr) {
-    Ptr = ReadOwnedPtr<T>();
+  inline void ReadOwnedPtr(T*& Ptr, bool AutoRegister = true) {
+    Ptr = ReadOwnedPtr<T>(AutoRegister);
   }
   
   template <typename T>
-  void ReadPtr(T*& PtrRef) {
-    ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef));
+  void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) {
+    ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), AllowBackpatch);
   }
   
   template <typename T>
-  void ReadPtr(const T*& PtrRef) {
-    ReadPtr(const_cast<T*&>(PtrRef));
+  void ReadPtr(const T*& PtrRef, bool AllowBackpatch = true) {
+    ReadPtr(const_cast<T*&>(PtrRef), AllowBackpatch);
   }            
 
-  void ReadUIntPtr(uintptr_t& PtrRef);
+  void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true);
   
   template <typename T>
   T& ReadRef() {
index 5642f37fac5d2abb7777c82bd91d6f2dd468256e..d4ed26b380a42143487a60635f54249a095fd570 100644 (file)
@@ -152,7 +152,7 @@ void Deserializer::RegisterPtr(unsigned PtrId, const void* Ptr) {
   SetPtr(E,Ptr);
 }
 
-void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) {
+void Deserializer::ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch) {
   unsigned PtrId = ReadInt();
   
   if (PtrId == 0) {
@@ -169,6 +169,9 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) {
   if (HasFinalPtr(E))
     PtrRef = GetFinalPtr(E);
   else {
+    assert (AllowBackpatch &&
+            "Client forbids backpatching for this pointer.");
+    
     // Register backpatch.  Check the freelist for a BPNode.
     BPNode* N;