From b12a82dbf4653b25d6bf3f55eb617339e9086dde Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 6 Nov 2007 22:21:14 +0000 Subject: [PATCH] Augmented ReadPtr and ReadOwnedPtr to control whether or not a pointer is allowed to be backpatched 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 | 21 ++++++++++++--------- 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 283e6035c79..9fdbc8cd965 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -114,33 +114,36 @@ public: void ReadCStr(std::vector& buff, bool isNullTerm=false); template - inline T* ReadOwnedPtr() { + inline T* ReadOwnedPtr(bool AutoRegister = true) { unsigned PtrId = ReadInt(); if (PtrId == 0) return NULL; T* x = SerializeTrait::Materialize(*this); - RegisterPtr(PtrId,x); + + if (AutoRegister) + RegisterPtr(PtrId,x); + return x; } template - inline void ReadOwnedPtr(T*& Ptr) { - Ptr = ReadOwnedPtr(); + inline void ReadOwnedPtr(T*& Ptr, bool AutoRegister = true) { + Ptr = ReadOwnedPtr(AutoRegister); } template - void ReadPtr(T*& PtrRef) { - ReadUIntPtr(reinterpret_cast(PtrRef)); + void ReadPtr(T*& PtrRef, bool AllowBackpatch = true) { + ReadUIntPtr(reinterpret_cast(PtrRef), AllowBackpatch); } template - void ReadPtr(const T*& PtrRef) { - ReadPtr(const_cast(PtrRef)); + void ReadPtr(const T*& PtrRef, bool AllowBackpatch = true) { + ReadPtr(const_cast(PtrRef), AllowBackpatch); } - void ReadUIntPtr(uintptr_t& PtrRef); + void ReadUIntPtr(uintptr_t& PtrRef, bool AllowBackpatch = true); template T& ReadRef() { diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index 5642f37fac5..d4ed26b380a 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;