llvm.org GIT mirror llvm / 872814a
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 Dan Gohman 9 years ago
11 changed file(s) with 20 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
948948
949949
950950

Named metadata is a collection of metadata. Metadata

951 nodes (but not metadata strings) and null are the only valid operands for
951 nodes (but not metadata strings) are the only valid operands for
952952 a named metadata.

953953
954954
Syntax:
955955

                  
                
956 ; An unnamed metadata node, which is referenced by the named metadata.
956 ; Some unnamed metadata nodes, which are referenced by the named metadata.
957 !0 = metadata !{metadata !"zero"}
957958 !1 = metadata !{metadata !"one"}
959 !2 = metadata !{metadata !"two"}
958960 ; A named metadata.
959 !name = !{null, !1}
961 !name = !{!0, !1, !2}
960962
961963
962964
303303 void dump() const;
304304
305305 /// replaceAllUsesWith - Replace all uses of debug info referenced by
306 /// this descriptor. After this completes, the current debug info value
307 /// is erased.
306 /// this descriptor.
308307 void replaceAllUsesWith(DIDescriptor &D);
309308 };
310309
148148 // critical code because it recursively visits all the MDNode's operands.
149149 const Function *getFunction() const;
150150
151 // destroy - Delete this node. Only when there are no uses.
152 void destroy();
153
154151 /// Profile - calculate a unique identifier for this MDNode to collapse
155152 /// duplicates
156153 void Profile(FoldingSetNodeID &ID) const;
161158 return V->getValueID() == MDNodeVal;
162159 }
163160 private:
161 // destroy - Delete this node. Only when there are no uses.
162 void destroy();
163
164164 bool isNotUniqued() const {
165165 return (getSubclassDataFromValue() & NotUniquedBit) != 0;
166166 }
232232 }
233233
234234 /// replaceAllUsesWith - Replace all uses of debug info referenced by
235 /// this descriptor. After this completes, the current debug info value
236 /// is erased.
235 /// this descriptor.
237236 void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
238237 if (!DbgNode)
239238 return;
248247 const MDNode *DN = D;
249248 const Value *V = cast_or_null(DN);
250249 Node->replaceAllUsesWith(const_cast(V));
251 Node->destroy();
252250 }
253251 }
254252
13841382 return 0;
13851383
13861384 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1387 DIDescriptor DIG(cast_or_null(NMD->getOperand(i)));
1385 DIDescriptor DIG(cast(NMD->getOperand(i)));
13881386 if (!DIG.isGlobalVariable())
13891387 continue;
13901388 if (DIGlobalVariable(DIG).getGlobal() == V)
545545 SmallVector Elts;
546546 if (Lex.getKind() != lltok::rbrace)
547547 do {
548 // Null is a special case since it is typeless.
549 if (EatIfPresent(lltok::kw_null)) {
550 Elts.push_back(0);
551 continue;
552 }
553
554548 if (ParseToken(lltok::exclaim, "Expected '!' here"))
555549 return true;
556550
802802 unsigned Size = Record.size();
803803 SmallVector Elts;
804804 for (unsigned i = 0; i != Size; ++i) {
805 if (Record[i] == ~0U) {
806 Elts.push_back(NULL);
807 continue;
808 }
809805 MDNode *MD = dyn_cast(MDValueList.getValueFwdRef(Record[i]));
810806 if (MD == 0)
811807 return Error("Malformed metadata record");
557557 Record.clear();
558558
559559 // Write named metadata operands.
560 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
561 if (NMD->getOperand(i))
562 Record.push_back(VE.getValueID(NMD->getOperand(i)));
563 else
564 Record.push_back(~0U);
565 }
560 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
561 Record.push_back(VE.getValueID(NMD->getOperand(i)));
566562 Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
567563 Record.clear();
568564 }
23182318 M->getNamedMetadata(Twine("llvm.dbg.lv.",
23192319 getRealLinkageName(F->getName())))) {
23202320 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
2321 DIVariable DV(cast_or_null(NMD->getOperand(i)));
2321 DIVariable DV(cast(NMD->getOperand(i)));
23222322 if (!DV || !Processed.insert(DV))
23232323 continue;
23242324 DbgScope *Scope = DbgScopeMap.lookup(DV.getContext());
27822782 M->getNamedMetadata(Twine("llvm.dbg.lv.",
27832783 getRealLinkageName(FName)))) {
27842784 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
2785 DIVariable DV(cast_or_null(NMD->getOperand(i)));
2785 DIVariable DV(cast(NMD->getOperand(i)));
27862786 if (!DV || !ProcessedVars.insert(DV))
27872787 continue;
27882788 DbgScope *Scope = AbstractScopes.lookup(DV.getContext());
637637 I = TheModule->named_metadata_begin(),
638638 E = TheModule->named_metadata_end(); I != E; ++I) {
639639 const NamedMDNode *NMD = I;
640 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
641 if (MDNode *MD = NMD->getOperand(i))
642 CreateMetadataSlot(MD);
643 }
640 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
641 CreateMetadataSlot(NMD->getOperand(i));
644642 }
645643
646644 // Add all the unnamed functions to the table.
14231421 Out << "!" << NMD->getName() << " = !{";
14241422 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
14251423 if (i) Out << ", ";
1426 if (MDNode *MD = NMD->getOperand(i))
1427 Out << '!' << Machine.getMetadataSlot(MD);
1428 else
1429 Out << "null";
1424 Out << '!' << Machine.getMetadataSlot(NMD->getOperand(i));
14301425 }
14311426 Out << "}\n";
14321427 }
388388 /// getOperand - Return specified operand.
389389 MDNode *NamedMDNode::getOperand(unsigned i) const {
390390 assert(i < getNumOperands() && "Invalid Operand number!");
391 return dyn_cast_or_null(&*getNMDOps(Operands)[i]);
391 return dyn_cast(&*getNMDOps(Operands)[i]);
392392 }
393393
394394 /// addOperand - Add metadata Operand.
22 ;; Simple NamedMDNode
33 !0 = metadata !{i32 42}
44 !1 = metadata !{metadata !"foo"}
5 !llvm.stuff = !{!0, !1, null}
5 !llvm.stuff = !{!0, !1}
66
77 !samename = !{!0, !1}
88 declare void @samename()