From dd479dd3fe396be3151349ee01be839fcb92e88e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 13 Nov 2007 00:13:57 +0000 Subject: [PATCH] Fixed bug with inconsistent serialization/deserialization in matching calls to BatchEmitOwnedPtrs and BatchReadOwnedPtrs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44032 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/Deserialize.h | 31 ++++++++++++++++++++++++++++++ include/llvm/Bitcode/Serialize.h | 17 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index f69bdffad28..8013f66f36d 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -228,6 +228,37 @@ public: Ptrs[i] = p; } + } + + template + void BatchReadOwnedPtrs(unsigned NumT1Ptrs, T1** Ptrs, + T2*& P2, T3*& P3, + bool A1=true, bool A2=true, bool A3=true) { + + BatchIDVec.clear(); + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + BatchIDVec.push_back(ReadPtrID()); + + SerializedPtrID ID2 = ReadPtrID(); + SerializedPtrID ID3 = ReadPtrID(); + + for (unsigned i = 0; i < NumT1Ptrs; ++i) { + SerializedPtrID& PtrID = BatchIDVec[i]; + + T1* p = PtrID ? SerializeTrait::Materialize(*this) : NULL; + + if (PtrID && A1) + RegisterPtr(PtrID,p); + + Ptrs[i] = p; + } + + P2 = (ID2) ? SerializeTrait::Materialize(*this) : NULL; + if (ID2 && A2) RegisterPtr(ID2,P2); + + P3 = (ID3) ? SerializeTrait::Materialize(*this) : NULL; + if (ID3 && A3) RegisterPtr(ID3,P3); } template diff --git a/include/llvm/Bitcode/Serialize.h b/include/llvm/Bitcode/Serialize.h index 2cd597e9059..0b99c575436 100644 --- a/include/llvm/Bitcode/Serialize.h +++ b/include/llvm/Bitcode/Serialize.h @@ -93,6 +93,23 @@ public: for (unsigned i = 0; i < NumPtrs; ++i) if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]); } + + template + void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, + T2* p2, T3* p3) { + + for (unsigned i = 0; i < NumT1Ptrs; ++i) + EmitPtr(Ptrs[i]); + + 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;