std::error_code globalCleanup();
std::error_code resolveGlobalAndAliasInits();
std::error_code parseMetadata();
+ std::error_code parseMetadataKinds();
+ std::error_code parseMetadataKindRecord(SmallVectorImpl<uint64_t> &Record);
std::error_code parseMetadataAttachment(Function &F);
ErrorOr<std::string> parseModuleTriple();
std::error_code parseUseLists();
}
}
+/// Parse a single METADATA_KIND record, inserting result in MDKindMap.
+std::error_code
+BitcodeReader::parseMetadataKindRecord(SmallVectorImpl<uint64_t> &Record) {
+ if (Record.size() < 2)
+ return error("Invalid record");
+
+ unsigned Kind = Record[0];
+ SmallString<8> Name(Record.begin() + 1, Record.end());
+
+ unsigned NewKind = TheModule->getMDKindID(Name.str());
+ if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
+ return error("Conflicting METADATA_KIND records");
+ return std::error_code();
+}
+
static int64_t unrotateSign(uint64_t U) { return U & 1 ? ~(U >> 1) : U >> 1; }
std::error_code BitcodeReader::parseMetadata() {
break;
}
case bitc::METADATA_KIND: {
- if (Record.size() < 2)
- return error("Invalid record");
+ // Support older bitcode files that had METADATA_KIND records in a
+ // block with METADATA_BLOCK_ID.
+ if (std::error_code EC = parseMetadataKindRecord(Record))
+ return EC;
+ break;
+ }
+ }
+ }
+#undef GET_OR_DISTINCT
+}
+
+/// Parse the metadata kinds out of the METADATA_KIND_BLOCK.
+std::error_code BitcodeReader::parseMetadataKinds() {
+ if (Stream.EnterSubBlock(bitc::METADATA_KIND_BLOCK_ID))
+ return error("Invalid record");
- unsigned Kind = Record[0];
- SmallString<8> Name(Record.begin()+1, Record.end());
+ SmallVector<uint64_t, 64> Record;
+
+ // Read all the records.
+ while (1) {
+ BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
- unsigned NewKind = TheModule->getMDKindID(Name.str());
- if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
- return error("Conflicting METADATA_KIND records");
+ switch (Entry.Kind) {
+ case BitstreamEntry::SubBlock: // Handled for us already.
+ case BitstreamEntry::Error:
+ return error("Malformed block");
+ case BitstreamEntry::EndBlock:
+ return std::error_code();
+ case BitstreamEntry::Record:
+ // The interesting case.
+ break;
+ }
+
+ // Read a record.
+ Record.clear();
+ unsigned Code = Stream.readRecord(Entry.ID, Record);
+ switch (Code) {
+ default: // Default behavior: ignore.
+ break;
+ case bitc::METADATA_KIND: {
+ if (std::error_code EC = parseMetadataKindRecord(Record))
+ return EC;
break;
}
}
}
-#undef GET_OR_DISTINCT
}
/// Decode a signed value stored with the sign bit in the LSB for dense VBR
if (std::error_code EC = parseMetadata())
return EC;
break;
+ case bitc::METADATA_KIND_BLOCK_ID:
+ if (std::error_code EC = parseMetadataKinds())
+ return EC;
+ break;
case bitc::FUNCTION_BLOCK_ID:
// If this is the first function body we've seen, reverse the
// FunctionsWithBodies list.
return "IDENTIFICATION_BLOCK_ID";
case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB";
case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK";
+ case bitc::METADATA_KIND_BLOCK_ID: return "METADATA_KIND_BLOCK";
case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK";
case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID";
case bitc::FUNCTION_SUMMARY_BLOCK_ID:
default:return nullptr;
STRINGIFY_CODE(METADATA, STRING)
STRINGIFY_CODE(METADATA, NAME)
- STRINGIFY_CODE(METADATA, KIND)
+ STRINGIFY_CODE(METADATA, KIND) // Older bitcode has it in a MODULE_BLOCK
STRINGIFY_CODE(METADATA, NODE)
STRINGIFY_CODE(METADATA, VALUE)
STRINGIFY_CODE(METADATA, OLD_NODE)
STRINGIFY_CODE(METADATA, IMPORTED_ENTITY)
STRINGIFY_CODE(METADATA, MODULE)
}
+ case bitc::METADATA_KIND_BLOCK_ID:
+ switch (CodeID) {
+ default:
+ return nullptr;
+ STRINGIFY_CODE(METADATA, KIND)
+ }
case bitc::USELIST_BLOCK_ID:
switch(CodeID) {
default:return nullptr;