Author: kremenek Date: Fri Nov 30 16:45:05 2007 New Revision: 44470 URL: http://llvm.org/viewvc/llvm-project?rev=44470&view=rev Log: Fixed subtle bug in Deserializer::JumpTo when jumping when the block-nesting information matching did not exactly match the underlying stream's scoping information.
Modified: llvm/trunk/include/llvm/Bitcode/Deserialize.h llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp Modified: llvm/trunk/include/llvm/Bitcode/Deserialize.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Deserialize.h?rev=44470&r1=44469&r2=44470&view=diff ============================================================================== --- llvm/trunk/include/llvm/Bitcode/Deserialize.h (original) +++ llvm/trunk/include/llvm/Bitcode/Deserialize.h Fri Nov 30 16:45:05 2007 @@ -125,7 +125,7 @@ llvm::SmallVector<Location,8> BlockStack; unsigned AbbrevNo; unsigned RecordCode; - Location StreamStart; + uint64_t StreamStart; //===----------------------------------------------------------===// // Public Interface. @@ -348,7 +348,7 @@ bool FinishedBlock(Location BlockLoc); bool JumpTo(const Location& BlockLoc); - void Rewind() { JumpTo(StreamStart); } + void Rewind(); bool AtEnd(); bool inRecord(); Modified: llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp?rev=44470&r1=44469&r2=44470&view=diff ============================================================================== --- llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp (original) +++ llvm/trunk/lib/Bitcode/Reader/Deserialize.cpp Fri Nov 30 16:45:05 2007 @@ -21,9 +21,8 @@ Deserializer::Deserializer(BitstreamReader& stream) : Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) { - - AdvanceStream(); - if (!AtEnd()) StreamStart = BlockStack.back(); + + StreamStart = Stream.GetCurrentBitNo(); } Deserializer::~Deserializer() { @@ -165,12 +164,11 @@ assert (!inRecord()); -// AdvanceStream(); + AdvanceStream(); -// assert (AbbrevNo == bitc::ENTER_SUBBLOCK); assert (!BlockStack.empty() || AtEnd()); - uint64_t LastBPos = StreamStart.BitNo; + uint64_t LastBPos = StreamStart; while (!BlockStack.empty()) { @@ -183,8 +181,11 @@ // destroy any accumulated context within the block scope. We then // jump to the position of the block and enter it. Stream.JumpToBit(LastBPos); + + if (BlockStack.size() == Stream.BlockScope.size()) + Stream.PopBlockScope(); + BlockStack.pop_back(); - Stream.PopBlockScope(); AbbrevNo = 0; AdvanceStream(); @@ -195,14 +196,19 @@ } // This block does not contain the block we are looking for. Pop it. + if (BlockStack.size() == Stream.BlockScope.size()) + Stream.PopBlockScope(); + BlockStack.pop_back(); - Stream.PopBlockScope(); + } // Check if we have popped our way to the outermost scope. If so, // we need to adjust our position. if (BlockStack.empty()) { - Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart.BitNo : LastBPos); + assert (Stream.BlockScope.empty()); + + Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart : LastBPos); AbbrevNo = 0; AdvanceStream(); } @@ -229,6 +235,18 @@ return true; } +void Deserializer::Rewind() { + while (!Stream.BlockScope.empty()) + Stream.PopBlockScope(); + + while (!BlockStack.empty()) + BlockStack.pop_back(); + + Stream.JumpToBit(StreamStart); + AbbrevNo = 0; +} + + unsigned Deserializer::getCurrentBlockID() { if (!inRecord()) AdvanceStream(); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits