Fixed subtle bug in Deserializer::JumpTo when jumping when the block-nesting

information matching did not exactly match the underlying stream's scoping
information.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44470 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2007-11-30 22:45:05 +00:00
parent 2a2a496aac
commit f64903b7d8
2 changed files with 29 additions and 11 deletions

View File

@ -125,7 +125,7 @@ private:
llvm::SmallVector<Location,8> BlockStack; llvm::SmallVector<Location,8> BlockStack;
unsigned AbbrevNo; unsigned AbbrevNo;
unsigned RecordCode; unsigned RecordCode;
Location StreamStart; uint64_t StreamStart;
//===----------------------------------------------------------===// //===----------------------------------------------------------===//
// Public Interface. // Public Interface.
@ -348,7 +348,7 @@ public:
bool FinishedBlock(Location BlockLoc); bool FinishedBlock(Location BlockLoc);
bool JumpTo(const Location& BlockLoc); bool JumpTo(const Location& BlockLoc);
void Rewind() { JumpTo(StreamStart); } void Rewind();
bool AtEnd(); bool AtEnd();
bool inRecord(); bool inRecord();

View File

@ -21,9 +21,8 @@ using namespace llvm;
Deserializer::Deserializer(BitstreamReader& stream) Deserializer::Deserializer(BitstreamReader& stream)
: Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) { : Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) {
AdvanceStream(); StreamStart = Stream.GetCurrentBitNo();
if (!AtEnd()) StreamStart = BlockStack.back();
} }
Deserializer::~Deserializer() { Deserializer::~Deserializer() {
@ -165,12 +164,11 @@ bool Deserializer::JumpTo(const Location& Loc) {
assert (!inRecord()); assert (!inRecord());
// AdvanceStream(); AdvanceStream();
// assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
assert (!BlockStack.empty() || AtEnd()); assert (!BlockStack.empty() || AtEnd());
uint64_t LastBPos = StreamStart.BitNo; uint64_t LastBPos = StreamStart;
while (!BlockStack.empty()) { while (!BlockStack.empty()) {
@ -183,8 +181,11 @@ bool Deserializer::JumpTo(const Location& Loc) {
// destroy any accumulated context within the block scope. We then // destroy any accumulated context within the block scope. We then
// jump to the position of the block and enter it. // jump to the position of the block and enter it.
Stream.JumpToBit(LastBPos); Stream.JumpToBit(LastBPos);
if (BlockStack.size() == Stream.BlockScope.size())
Stream.PopBlockScope();
BlockStack.pop_back(); BlockStack.pop_back();
Stream.PopBlockScope();
AbbrevNo = 0; AbbrevNo = 0;
AdvanceStream(); AdvanceStream();
@ -195,14 +196,19 @@ bool Deserializer::JumpTo(const Location& Loc) {
} }
// This block does not contain the block we are looking for. Pop it. // This block does not contain the block we are looking for. Pop it.
if (BlockStack.size() == Stream.BlockScope.size())
Stream.PopBlockScope();
BlockStack.pop_back(); BlockStack.pop_back();
Stream.PopBlockScope();
} }
// Check if we have popped our way to the outermost scope. If so, // Check if we have popped our way to the outermost scope. If so,
// we need to adjust our position. // we need to adjust our position.
if (BlockStack.empty()) { if (BlockStack.empty()) {
Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart.BitNo : LastBPos); assert (Stream.BlockScope.empty());
Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart : LastBPos);
AbbrevNo = 0; AbbrevNo = 0;
AdvanceStream(); AdvanceStream();
} }
@ -229,6 +235,18 @@ bool Deserializer::JumpTo(const Location& Loc) {
return true; 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() { unsigned Deserializer::getCurrentBlockID() {
if (!inRecord()) if (!inRecord())
AdvanceStream(); AdvanceStream();