diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-21 18:54:18 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-21 18:54:18 +0000 |
commit | 872814ae048df032bddf9299c850f5bda08299a9 (patch) | |
tree | 8abc3d283bd51ea3430c80b7c69f84b8e6067010 /lib | |
parent | ec237ffd28f1408f524dc134220d8502e167f4d9 (diff) | |
download | llvm-872814ae048df032bddf9299c850f5bda08299a9.tar.gz llvm-872814ae048df032bddf9299c850f5bda08299a9.tar.bz2 llvm-872814ae048df032bddf9299c850f5bda08299a9.tar.xz |
Disallow null as a named metadata operand.
Make MDNode::destroy private.
Fix the one thing that used MDNode::destroy, outside of MDNode itself.
One should never delete or destroy an MDNode explicitly. MDNodes
implicitly go away when there are no references to them (implementation
details aside).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109028 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/DebugInfo.cpp | 6 | ||||
-rw-r--r-- | lib/AsmParser/LLParser.cpp | 6 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 4 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 2 |
7 files changed, 10 insertions, 31 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index ca6c2e6d72..277edefe7b 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -233,8 +233,7 @@ unsigned DIArray::getNumElements() const { } /// replaceAllUsesWith - Replace all uses of debug info referenced by -/// this descriptor. After this completes, the current debug info value -/// is erased. +/// this descriptor. void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { if (!DbgNode) return; @@ -249,7 +248,6 @@ void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { const MDNode *DN = D; const Value *V = cast_or_null<Value>(DN); Node->replaceAllUsesWith(const_cast<Value*>(V)); - Node->destroy(); } } @@ -1385,7 +1383,7 @@ static Value *findDbgGlobalDeclare(GlobalVariable *V) { return 0; for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - DIDescriptor DIG(cast_or_null<MDNode>(NMD->getOperand(i))); + DIDescriptor DIG(cast<MDNode>(NMD->getOperand(i))); if (!DIG.isGlobalVariable()) continue; if (DIGlobalVariable(DIG).getGlobal() == V) diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 221b994db5..06229d78e2 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -546,12 +546,6 @@ bool LLParser::ParseNamedMetadata() { SmallVector<MDNode *, 8> Elts; if (Lex.getKind() != lltok::rbrace) 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 f486b51cae..7d82321afc 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -803,10 +803,6 @@ bool BitcodeReader::ParseMetadata() { unsigned Size = Record.size(); SmallVector<MDNode *, 8> Elts; for (unsigned i = 0; i != Size; ++i) { - if (Record[i] == ~0U) { - Elts.push_back(NULL); - continue; - } MDNode *MD = dyn_cast<MDNode>(MDValueList.getValueFwdRef(Record[i])); if (MD == 0) return Error("Malformed metadata record"); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 985c16c783..64c2dfaee8 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -558,12 +558,8 @@ static void WriteModuleMetadata(const ValueEnumerator &VE, Record.clear(); // Write named metadata operands. - for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - if (NMD->getOperand(i)) - Record.push_back(VE.getValueID(NMD->getOperand(i))); - else - Record.push_back(~0U); - } + for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) + Record.push_back(VE.getValueID(NMD->getOperand(i))); Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0); Record.clear(); } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index a1f646a425..5f7d052ec0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2319,7 +2319,7 @@ DwarfDebug::collectVariableInfo(const MachineFunction *MF, M->getNamedMetadata(Twine("llvm.dbg.lv.", getRealLinkageName(F->getName())))) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - DIVariable DV(cast_or_null<MDNode>(NMD->getOperand(i))); + DIVariable DV(cast<MDNode>(NMD->getOperand(i))); if (!DV || !Processed.insert(DV)) continue; DbgScope *Scope = DbgScopeMap.lookup(DV.getContext()); @@ -2783,7 +2783,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { M->getNamedMetadata(Twine("llvm.dbg.lv.", getRealLinkageName(FName)))) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - DIVariable DV(cast_or_null<MDNode>(NMD->getOperand(i))); + DIVariable DV(cast<MDNode>(NMD->getOperand(i))); if (!DV || !ProcessedVars.insert(DV)) continue; DbgScope *Scope = AbstractScopes.lookup(DV.getContext()); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index c371ab97cd..7d51be1150 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -638,10 +638,8 @@ void SlotTracker::processModule() { I = TheModule->named_metadata_begin(), E = TheModule->named_metadata_end(); I != E; ++I) { const NamedMDNode *NMD = I; - for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - if (MDNode *MD = NMD->getOperand(i)) - CreateMetadataSlot(MD); - } + for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) + CreateMetadataSlot(NMD->getOperand(i)); } // Add all the unnamed functions to the table. @@ -1424,10 +1422,7 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) { Out << "!" << NMD->getName() << " = !{"; for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { if (i) Out << ", "; - if (MDNode *MD = NMD->getOperand(i)) - Out << '!' << Machine.getMetadataSlot(MD); - else - Out << "null"; + Out << '!' << Machine.getMetadataSlot(NMD->getOperand(i)); } Out << "}\n"; } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index a89cffd8e0..cc4a68ec41 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -389,7 +389,7 @@ unsigned NamedMDNode::getNumOperands() const { /// getOperand - Return specified operand. MDNode *NamedMDNode::getOperand(unsigned i) const { assert(i < getNumOperands() && "Invalid Operand number!"); - return dyn_cast_or_null<MDNode>(&*getNMDOps(Operands)[i]); + return dyn_cast<MDNode>(&*getNMDOps(Operands)[i]); } /// addOperand - Add metadata Operand. |