[llvm] r232417 - AsmWriter: Handle broken metadata nodes

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Mar 16 14:21:10 PDT 2015


Author: dexonsmith
Date: Mon Mar 16 16:21:10 2015
New Revision: 232417

URL: http://llvm.org/viewvc/llvm-project?rev=232417&view=rev
Log:
AsmWriter: Handle broken metadata nodes

Print out temporary `MDNode`s so we don't crash in the verifier (or
during `dump()` output).

Modified:
    llvm/trunk/lib/IR/AsmWriter.cpp
    llvm/trunk/unittests/IR/MetadataTest.cpp

Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=232417&r1=232416&r2=232417&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Mon Mar 16 16:21:10 2015
@@ -1916,10 +1916,10 @@ static void WriteMDNodeBodyInternal(raw_
                                     TypePrinting *TypePrinter,
                                     SlotTracker *Machine,
                                     const Module *Context) {
-  assert(!Node->isTemporary() && "Unexpected forward declaration");
-
   if (Node->isDistinct())
     Out << "distinct ";
+  else if (Node->isTemporary())
+    Out << "<temporary!> "; // Handle broken code.
 
   switch (Node->getMetadataID()) {
   default:

Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=232417&r1=232416&r2=232417&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Mon Mar 16 16:21:10 2015
@@ -251,6 +251,22 @@ TEST_F(MDNodeTest, Print) {
     EXPECT_EQ(Expected_, Actual_);                                             \
   } while (false)
 
+TEST_F(MDNodeTest, PrintTemporary) {
+  MDNode *Arg = getNode();
+  TempMDNode Temp = MDNode::getTemporary(Context, Arg);
+  MDNode *N = getNode(Temp.get());
+  Module M("test", Context);
+  NamedMDNode *NMD = M.getOrInsertNamedMetadata("named");
+  NMD->addOperand(N);
+
+  EXPECT_PRINTER_EQ("!0 = !{!1}", N->print(OS, &M));
+  EXPECT_PRINTER_EQ("!1 = <temporary!> !{!2}", Temp->print(OS, &M));
+  EXPECT_PRINTER_EQ("!2 = !{}", Arg->print(OS, &M));
+
+  // Cleanup.
+  Temp->replaceAllUsesWith(Arg);
+}
+
 TEST_F(MDNodeTest, PrintFromModule) {
   Constant *C = ConstantInt::get(Type::getInt32Ty(Context), 7);
   MDString *S = MDString::get(Context, "foo");





More information about the llvm-commits mailing list