diff options
author | Devang Patel <dpatel@apple.com> | 2010-01-05 21:47:32 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-01-05 21:47:32 +0000 |
commit | 69d02e0a174151e0f129731452e819b91d1ab90e (patch) | |
tree | 490d8aa9eadf369e637c7721fe098eb11c746f42 /lib | |
parent | 6ae68a28b9c277e2e938e3520d0177bacbf57250 (diff) | |
download | external_llvm-69d02e0a174151e0f129731452e819b91d1ab90e.zip external_llvm-69d02e0a174151e0f129731452e819b91d1ab90e.tar.gz external_llvm-69d02e0a174151e0f129731452e819b91d1ab90e.tar.bz2 |
Allow null to be an element of NamedMDNode. e.g. !llvm.stuff = !{!0, !1, null}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 6 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 10 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 2 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 11 |
5 files changed, 21 insertions, 11 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index ca001c1..99ddeb6 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -512,6 +512,12 @@ bool LLParser::ParseNamedMetadata() { SmallVector<MDNode *, 8> Elts; do { + // Null is a special case since it is typeless. + if (EatIfPresent(lltok::kw_null)) { + Elts.push_back(0); + continue; + } + if (ParseToken(lltok::exclaim, "Expected '!' here")) return true; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index c8097a0..33da5e4 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -789,9 +789,13 @@ bool BitcodeReader::ParseMetadata() { unsigned Size = Record.size(); SmallVector<MDNode *, 8> Elts; for (unsigned i = 0; i != Size; ++i) { - Value *MD = MDValueList.getValueFwdRef(Record[i]); - if (MDNode *B = dyn_cast_or_null<MDNode>(MD)) - Elts.push_back(B); + if (Record[i] == ~0U) + Elts.push_back(NULL); + else { + Value *MD = MDValueList.getValueFwdRef(Record[i]); + if (MDNode *B = dyn_cast_or_null<MDNode>(MD)) + Elts.push_back(B); + } } Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(), Elts.size(), TheModule); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index c78a30e..ce9036b 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -540,7 +540,7 @@ static void WriteModuleMetadata(const ValueEnumerator &VE, if (NMD->getOperand(i)) Record.push_back(VE.getValueID(NMD->getOperand(i))); else - Record.push_back(0); + Record.push_back(~0U); } Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0); Record.clear(); diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 861de84..c409c20 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -223,7 +223,8 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) { if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) { for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) - EnumerateValue(N->getOperand(i)); + if (MDNode *E = N->getOperand(i)) + EnumerateValue(E); MDValues.push_back(std::make_pair(MD, 1U)); MDValueMap[MD] = Values.size(); return; diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 950eb0b..7cb5a7c 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -615,8 +615,7 @@ void SlotTracker::processModule() { E = TheModule->named_metadata_end(); I != E; ++I) { const NamedMDNode *NMD = I; for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - // FIXME: Change accessor to be type safe. - if (MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i))) + if (MDNode *MD = NMD->getOperand(i)) CreateMetadataSlot(MD); } } @@ -1370,10 +1369,10 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) { Out << "!" << NMD->getName() << " = !{"; for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { if (i) Out << ", "; - // FIXME: Change accessor to be typesafe. - // FIXME: This doesn't handle null?? - MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i)); - Out << '!' << Machine.getMetadataSlot(MD); + if (MDNode *MD = NMD->getOperand(i)) + Out << '!' << Machine.getMetadataSlot(MD); + else + Out << "null"; } Out << "}\n"; } |