Change Metadata Index emission in the bitcode to use 2x32 bits for the placeholder

The Bitstream reader and writer are limited to handle a "size_t" at
most, which means that we can't backpatch and read back a 64bits
value on 32 bits platform.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290693 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mehdi Amini 2016-12-28 23:45:54 +00:00
parent 90bcc71ffb
commit 6fc58a7278
3 changed files with 10 additions and 4 deletions

View File

@ -284,7 +284,7 @@ private:
default: llvm_unreachable("Unknown encoding!");
case BitCodeAbbrevOp::Fixed:
if (Op.getEncodingData())
Emit64(V, (unsigned)Op.getEncodingData());
Emit((unsigned)V, (unsigned)Op.getEncodingData());
break;
case BitCodeAbbrevOp::VBR:
if (Op.getEncodingData())

View File

@ -1920,7 +1920,8 @@ void ModuleBitcodeWriter::writeModuleMetadata() {
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_INDEX_OFFSET));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 64));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
unsigned OffsetAbbrev = Stream.EmitAbbrev(Abbv);
Abbv = new BitCodeAbbrev();
@ -1939,7 +1940,7 @@ void ModuleBitcodeWriter::writeModuleMetadata() {
// which is written after the records, so that it can include
// the offset of each entry. The placeholder offset will be
// updated after all records are emitted.
uint64_t Vals[] = {0};
uint64_t Vals[] = {0, 0};
Stream.EmitRecord(bitc::METADATA_INDEX_OFFSET, Vals, OffsetAbbrev);
}

View File

@ -609,7 +609,12 @@ static bool ParseBlock(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo,
// and validate its forward reference offset was correct!
if (BlockID == bitc::METADATA_BLOCK_ID) {
if (Code == bitc::METADATA_INDEX_OFFSET) {
MetadataIndexOffset = Stream.GetCurrentBitNo() + Record[0];
if (Record.size() != 2)
outs() << "(Invalid record)";
else {
auto Offset = Record[0] + (Record[1] << 32);
MetadataIndexOffset = Stream.GetCurrentBitNo() + Offset;
}
}
if (Code == bitc::METADATA_INDEX) {
outs() << " (offset ";