Bitcode: Correctly handle Fixed and VBR arrays in BitstreamCursor::skipRecord().

The assertions were wrong; we need to call getEncodingData() on the element,
not the array. While here, simplify the skipRecord() implementation for Fixed
and Char6 arrays. This is tested by the code I added to llvm-bcanalyzer
which makes sure that we can skip any record.

Differential Revision: https://reviews.llvm.org/D27241

llvm-svn: 288315
This commit is contained in:
Peter Collingbourne 2016-12-01 05:47:58 +00:00
parent 2eed75926c
commit cf2750a501
2 changed files with 10 additions and 8 deletions

View File

@ -131,18 +131,16 @@ void BitstreamCursor::skipRecord(unsigned AbbrevID) {
default: default:
report_fatal_error("Array element type can't be an Array or a Blob"); report_fatal_error("Array element type can't be an Array or a Blob");
case BitCodeAbbrevOp::Fixed: case BitCodeAbbrevOp::Fixed:
assert((unsigned)Op.getEncodingData() <= MaxChunkSize); assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize);
for (; NumElts; --NumElts) JumpToBit(GetCurrentBitNo() + NumElts * EltEnc.getEncodingData());
Read((unsigned)EltEnc.getEncodingData());
break; break;
case BitCodeAbbrevOp::VBR: case BitCodeAbbrevOp::VBR:
assert((unsigned)Op.getEncodingData() <= MaxChunkSize); assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize);
for (; NumElts; --NumElts) for (; NumElts; --NumElts)
ReadVBR64((unsigned)EltEnc.getEncodingData()); ReadVBR64((unsigned)EltEnc.getEncodingData());
break; break;
case BitCodeAbbrevOp::Char6: case BitCodeAbbrevOp::Char6:
for (; NumElts; --NumElts) JumpToBit(GetCurrentBitNo() + NumElts * 6);
Read(6);
break; break;
} }
continue; continue;

View File

@ -567,7 +567,7 @@ static bool ParseBlock(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo,
++BlockStats.NumRecords; ++BlockStats.NumRecords;
StringRef Blob; StringRef Blob;
unsigned CurrentRecordPos = Stream.getCurrentByteNo(); unsigned CurrentRecordPos = Stream.GetCurrentBitNo();
unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob); unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob);
// Increment the # occurrences of this code. // Increment the # occurrences of this code.
@ -608,7 +608,7 @@ static bool ParseBlock(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo,
SHA1 Hasher; SHA1 Hasher;
StringRef Hash; StringRef Hash;
{ {
int BlockSize = CurrentRecordPos - BlockEntryPos; int BlockSize = (CurrentRecordPos / 8) - BlockEntryPos;
auto Ptr = Stream.getPointerToByte(BlockEntryPos, BlockSize); auto Ptr = Stream.getPointerToByte(BlockEntryPos, BlockSize);
Hasher.update(ArrayRef<uint8_t>(Ptr, BlockSize)); Hasher.update(ArrayRef<uint8_t>(Ptr, BlockSize));
Hash = Hasher.result(); Hash = Hasher.result();
@ -675,6 +675,10 @@ static bool ParseBlock(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo,
outs() << "\n"; outs() << "\n";
} }
// Make sure that we can skip the current record.
Stream.JumpToBit(CurrentRecordPos);
Stream.skipRecord(Entry.ID);
} }
} }