diff options
Diffstat (limited to 'lib/Bitcode/Reader')
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 12 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.h | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index b3f0776d29..f486b51cae 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -39,6 +39,7 @@ void BitcodeReader::FreeState() { std::vector<BasicBlock*>().swap(FunctionBBs); std::vector<Function*>().swap(FunctionsWithBodies); DeferredFunctionInfo.clear(); + MDKindMap.clear(); } //===----------------------------------------------------------------------===// @@ -859,13 +860,12 @@ bool BitcodeReader::ParseMetadata() { SmallString<8> Name; Name.resize(RecordLength-1); unsigned Kind = Record[0]; - (void) Kind; for (unsigned i = 1; i != RecordLength; ++i) Name[i-1] = Record[i]; unsigned NewKind = TheModule->getMDKindID(Name.str()); - assert(Kind == NewKind && - "FIXME: Unable to handle custom metadata mismatch!");(void)NewKind; + if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second) + return Error("Conflicting METADATA_KIND records"); break; } } @@ -1621,8 +1621,12 @@ bool BitcodeReader::ParseMetadataAttachment() { Instruction *Inst = InstructionList[Record[0]]; for (unsigned i = 1; i != RecordLength; i = i+2) { unsigned Kind = Record[i]; + DenseMap<unsigned, unsigned>::iterator I = + MDKindMap.find(Kind); + if (I == MDKindMap.end()) + return Error("Invalid metadata kind ID"); Value *Node = MDValueList.getValueFwdRef(Record[i+1]); - Inst->setMetadata(Kind, cast<MDNode>(Node)); + Inst->setMetadata(I->second, cast<MDNode>(Node)); } break; } diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h index 55c71f7c88..a5ab5d29e9 100644 --- a/lib/Bitcode/Reader/BitcodeReader.h +++ b/lib/Bitcode/Reader/BitcodeReader.h @@ -156,6 +156,9 @@ class BitcodeReader : public GVMaterializer { // stored here with their replacement function. typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap; UpgradedIntrinsicMap UpgradedIntrinsics; + + // Map the bitcode's custom MDKind ID to the Module's MDKind ID. + DenseMap<unsigned, unsigned> MDKindMap; // After the module header has been read, the FunctionsWithBodies list is // reversed. This keeps track of whether we've done this yet. |