diff options
-rw-r--r-- | include/llvm/Bitcode/Deserialize.h | 21 | ||||
-rw-r--r-- | lib/Bitcode/Reader/Deserialize.cpp | 5 |
2 files changed, 16 insertions, 10 deletions
diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 283e603..9fdbc8c 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -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() { diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index 5642f37..d4ed26b 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -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; |