From 9eeccd939e4c4f651842709d3c63445f8775fcac Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 1 Nov 2007 00:57:37 +0000 Subject: Rewrote backpatcher. Backpatcher now stores the "has final pointer" flag in the **key** of the backpatch map, as opposed to the mapped value which contains either the final pointer, or a pointer to a chain of pointers that need to be backpatched. The bit flag was moved to the key because we were erroneously assuming that the backpatched pointers would be at an alignment of >= 2 bytes, which obviously doesn't work for character strings. Now we just steal the bit from the key. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43595 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/Deserialize.cpp | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'lib/Bitcode') diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index 9bc0f15..e5a4d18 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -25,7 +25,7 @@ Deserializer::~Deserializer() { #ifdef NDEBUG for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I) - assert (I->second.hasFinalPtr() && + assert (I->first.hasFinalPtr() && "Some pointers were not backpatched."); #endif } @@ -99,9 +99,11 @@ void Deserializer::ReadCStr(std::vector& buff, bool isNullTerm) { } void Deserializer::RegisterPtr(unsigned PtrId, const void* Ptr) { - BPatchEntry& E = BPatchMap[PtrId]; - assert (!E.hasFinalPtr() && "Pointer already registered."); - E.setFinalPtr(FreeList,Ptr); + MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId)); + + assert (!HasFinalPtr(E) && "Pointer already registered."); + + SetPtr(E,Ptr); } void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) { @@ -111,11 +113,11 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) { PtrRef = 0; return; } + + MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId)); - BPatchEntry& E = BPatchMap[PtrId]; - - if (E.hasFinalPtr()) - PtrRef = E.getFinalPtr(); + if (HasFinalPtr(E)) + PtrRef = GetFinalPtr(E); else { // Register backpatch. Check the freelist for a BPNode. BPNode* N; @@ -127,8 +129,8 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef) { else // No available BPNode. Allocate one. N = (BPNode*) Allocator.Allocate(); - new (N) BPNode(E.getBPNode(),PtrRef); - E.setBPNode(N); + new (N) BPNode(GetBPNode(E),PtrRef); + SetBPNode(E,N); } } @@ -137,32 +139,28 @@ uintptr_t Deserializer::ReadInternalRefPtr() { assert (PtrId != 0 && "References cannot refer the NULL address."); - BPatchEntry& E = BPatchMap[PtrId]; + MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId)); - assert (E.hasFinalPtr() && + assert (!HasFinalPtr(E) && "Cannot backpatch references. Object must be already deserialized."); - return E.getFinalPtr(); + return GetFinalPtr(E); } -void Deserializer::BPatchEntry::setFinalPtr(BPNode*& FreeList, const void* P) { - assert (!hasFinalPtr()); - - // Perform backpatching. - +void Deserializer::BPEntry::SetPtr(BPNode*& FreeList, void* P) { BPNode* Last = NULL; - for (BPNode* N = getBPNode() ; N != NULL; N = N->Next) { + for (BPNode* N = Head; N != NULL; N=N->Next) { Last = N; N->PtrRef |= reinterpret_cast(P); } if (Last) { Last->Next = FreeList; - FreeList = getBPNode(); + FreeList = Head; } - Ptr = reinterpret_cast(P); + Ptr = const_cast(P); } -- cgit v1.1