From b6c40f3f1b580fc85f1ffb38fff40acc383bb6df Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 17 Nov 2007 03:34:33 +0000 Subject: [PATCH] Reverted patch 44199: http://llvm.org/viewvc/llvm-project?rev=44199&view=rev This patch completely broke serialization due to an invariant I assumed but did not hold. The assumed invariant was that all pointer IDs emitted by a call to BatchEmitOwnedPtrs would be consecutive. This is only the case if there has been no forward references to an owned pointer (and hence already registered with the Serializer object). llvm-svn: 44203 --- llvm/include/llvm/Bitcode/Deserialize.h | 86 +++++++------------------ llvm/include/llvm/Bitcode/Serialize.h | 72 +++++++-------------- 2 files changed, 46 insertions(+), 112 deletions(-) diff --git a/llvm/include/llvm/Bitcode/Deserialize.h b/llvm/include/llvm/Bitcode/Deserialize.h index ef25da71409e..9b84c8ed4579 100644 --- a/llvm/include/llvm/Bitcode/Deserialize.h +++ b/llvm/include/llvm/Bitcode/Deserialize.h @@ -137,13 +137,7 @@ public: uint64_t ReadInt(); int64_t ReadSInt(); - SerializedPtrID ReadPtrID() { return (SerializedPtrID) ReadInt(); } - - SerializedPtrID ReadDiffPtrID(SerializedPtrID& PrevID) { - bool x = ReadBool(); - return (SerializedPtrID) (x ? (PrevID+1) : 0); - } bool ReadBool() { @@ -189,7 +183,7 @@ public: bool A1=true, bool A2=true) { SerializedPtrID ID1 = ReadPtrID(); - SerializedPtrID ID2 = ReadDiffPtrID(ID2); + SerializedPtrID ID2 = ReadPtrID(); P1 = (ID1) ? SerializeTrait::Create(*this) : NULL; if (ID1 && A1) RegisterPtr(ID1,P1); @@ -203,8 +197,8 @@ public: bool A1=true, bool A2=true, bool A3=true) { SerializedPtrID ID1 = ReadPtrID(); - SerializedPtrID ID2 = ReadDiffPtrID(ID1); - SerializedPtrID ID3 = ReadDiffPtrID(ID2); + SerializedPtrID ID2 = ReadPtrID(); + SerializedPtrID ID3 = ReadPtrID(); P1 = (ID1) ? SerializeTrait::Create(*this) : NULL; if (ID1 && A1) RegisterPtr(ID1,P1); @@ -216,37 +210,12 @@ public: if (ID3 && A3) RegisterPtr(ID3,P3); } - template - void BatchReadOwnedPtrs(T1*& P1, T2*& P2, T3*& P3, T4*& P4, - bool A1=true, bool A2=true, bool A3=true, bool A4=true) { - - SerializedPtrID ID1 = ReadPtrID(); - SerializedPtrID ID2 = ReadDiffPtrID(ID1); - SerializedPtrID ID3 = ReadDiffPtrID(ID2); - SerializedPtrID ID4 = ReadDiffPtrID(ID3); - - P1 = (ID1) ? SerializeTrait::Create(*this) : NULL; - if (ID1 && A1) RegisterPtr(ID1,P1); - - P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; - if (ID2 && A2) RegisterPtr(ID2,P2); - - P3 = (ID3) ? SerializeTrait::Create(*this) : NULL; - if (ID3 && A3) RegisterPtr(ID3,P3); - - P4 = (ID4) ? SerializeTrait::Create(*this) : NULL; - if (ID4 && A4) RegisterPtr(ID4,P4); - } - template void BatchReadOwnedPtrs(unsigned NumPtrs, T** Ptrs, bool AutoRegister=true) { llvm::SmallVector BatchIDVec; - SerializedPtrID TempPtrID; - for (unsigned i = 0; i < NumPtrs; ++i) { - TempPtrID = i ? ReadDiffPtrID(TempPtrID) : ReadPtrID(); - BatchIDVec.push_back(TempPtrID); - } + for (unsigned i = 0; i < NumPtrs; ++i) + BatchIDVec.push_back(ReadPtrID()); for (unsigned i = 0; i < NumPtrs; ++i) { SerializedPtrID& PtrID = BatchIDVec[i]; @@ -263,19 +232,13 @@ public: template void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, bool A1=true, bool A2=true) { - - SerializedPtrID ID2 = ReadPtrID(); - SerializedPtrID TempID = ID2; - + llvm::SmallVector BatchIDVec; + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + BatchIDVec.push_back(ReadPtrID()); - for (unsigned i = 0; i < NumT1Ptrs; ++i) { - TempID = ReadDiffPtrID(TempID); - BatchIDVec.push_back(TempID); - } - - P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; - if (ID2 && A2) RegisterPtr(ID2,P2); + SerializedPtrID ID2 = ReadPtrID(); for (unsigned i = 0; i < NumT1Ptrs; ++i) { SerializedPtrID& PtrID = BatchIDVec[i]; @@ -286,31 +249,24 @@ public: RegisterPtr(PtrID,p); Ptrs[i] = p; - } + } + + P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; + if (ID2 && A2) RegisterPtr(ID2,P2); } template void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, T2*& P2, T3*& P3, bool A1=true, bool A2=true, bool A3=true) { - - SerializedPtrID ID2 = ReadPtrID(); - SerializedPtrID ID3 = ReadDiffPtrID(ID2); - - SerializedPtrID TempID = ID3; llvm::SmallVector BatchIDVec; - for (unsigned i = 0; i < NumT1Ptrs; ++i) { - TempID = ReadDiffPtrID(TempID); - BatchIDVec.push_back(TempID); - } + for (unsigned i = 0; i < NumT1Ptrs; ++i) + BatchIDVec.push_back(ReadPtrID()); - P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; - if (ID2 && A2) RegisterPtr(ID2,P2); - - P3 = (ID3) ? SerializeTrait::Create(*this) : NULL; - if (ID3 && A3) RegisterPtr(ID3,P3); + SerializedPtrID ID2 = ReadPtrID(); + SerializedPtrID ID3 = ReadPtrID(); for (unsigned i = 0; i < NumT1Ptrs; ++i) { SerializedPtrID& PtrID = BatchIDVec[i]; @@ -322,6 +278,12 @@ public: Ptrs[i] = p; } + + P2 = (ID2) ? SerializeTrait::Create(*this) : NULL; + if (ID2 && A2) RegisterPtr(ID2,P2); + + P3 = (ID3) ? SerializeTrait::Create(*this) : NULL; + if (ID3 && A3) RegisterPtr(ID3,P3); } template diff --git a/llvm/include/llvm/Bitcode/Serialize.h b/llvm/include/llvm/Bitcode/Serialize.h index 9430bb10a42e..60d9cb2c992d 100644 --- a/llvm/include/llvm/Bitcode/Serialize.h +++ b/llvm/include/llvm/Bitcode/Serialize.h @@ -45,28 +45,6 @@ public: void EmitCStr(const char* cstr); void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); } - - SerializedPtrID EmitPtr(const void* ptr,bool) { - SerializedPtrID ptr_id = getPtrId(ptr); - EmitInt(ptr_id); - return ptr_id; - } - - SerializedPtrID EmitDiffPtrID(const void* ptr, SerializedPtrID PrevID) { - assert (!isRegistered(ptr)); - SerializedPtrID ptr_id = getPtrId(ptr); - - if (ptr_id == 0) - EmitBool(false); - else { - assert (ptr_id > PrevID); - assert (PrevID == 0 || ptr_id - PrevID == 1); - EmitBool(true); - } - - return ptr_id; - } - template void EmitRef(const T& ref) { EmitPtr(&ref); } @@ -79,21 +57,17 @@ public: template void BatchEmitOwnedPtrs(T1* p1, T2* p2) { - // Optimization: Only emit the differences between the IDs. Most of - // the time this difference will be "1", thus resulting in fewer bits. - assert (!isRegistered(p1)); - assert (!isRegistered(p2)); - - EmitDiffPtrID(p2,EmitPtr(p1,true)); - + EmitPtr(p1); + EmitPtr(p2); if (p1) SerializeTrait::Emit(*this,*p1); if (p2) SerializeTrait::Emit(*this,*p2); } template void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3) { - EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1))); - + EmitPtr(p1); + EmitPtr(p2); + EmitPtr(p3); if (p1) SerializeTrait::Emit(*this,*p1); if (p2) SerializeTrait::Emit(*this,*p2); if (p3) SerializeTrait::Emit(*this,*p3); @@ -101,8 +75,10 @@ public: template void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3, T4& p4) { - EmitDiffPtrID(p4,EmitDiffPtrID(p3,EmitDiffPtrID(p2,EmitPtr(p1)))); - + EmitPtr(p1); + EmitPtr(p2); + EmitPtr(p3); + EmitPtr(p4); if (p1) SerializeTrait::Emit(*this,*p1); if (p2) SerializeTrait::Emit(*this,*p2); if (p3) SerializeTrait::Emit(*this,*p3); @@ -111,12 +87,8 @@ public: template void BatchEmitOwnedPtrs(unsigned NumPtrs, T* const * Ptrs) { - SerializedPtrID ID; - - for (unsigned i = 0; i < NumPtrs; ++i) { - if (i == 0) ID = EmitPtr(Ptrs[i],true); - else ID = EmitDiffPtrID(Ptrs[i],ID); - } + for (unsigned i = 0; i < NumPtrs; ++i) + EmitPtr(Ptrs[i]); for (unsigned i = 0; i < NumPtrs; ++i) if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); @@ -125,32 +97,32 @@ public: template void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) { - SerializedPtrID ID = EmitPtr(p2,true); - for (unsigned i = 0; i < NumT1Ptrs; ++i) - ID = EmitDiffPtrID(Ptrs[i],ID); + EmitPtr(Ptrs[i]); + + EmitPtr(p2); + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); if (p2) SerializeTrait::Emit(*this,*p2); - - for (unsigned i = 0; i < NumT1Ptrs; ++i) - if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); } template void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2, T3* p3) { - SerializedPtrID TempID = EmitDiffPtrID(p3,EmitPtr(p2,true)); - for (unsigned i = 0; i < NumT1Ptrs; ++i) - TempID = EmitDiffPtrID(Ptrs[i],TempID); + EmitPtr(Ptrs[i]); - if (p2) SerializeTrait::Emit(*this,*p2); - if (p3) SerializeTrait::Emit(*this,*p3); + EmitPtr(p2); + EmitPtr(p3); for (unsigned i = 0; i < NumT1Ptrs; ++i) if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); + if (p2) SerializeTrait::Emit(*this,*p2); + if (p3) SerializeTrait::Emit(*this,*p3); } bool isRegistered(const void* p) const;