fix PR7105 by enumerating MDNodes on all @llvm.foo
authorChris Lattner <sabre@nondot.org>
Mon, 10 May 2010 20:53:17 +0000 (20:53 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 10 May 2010 20:53:17 +0000 (20:53 +0000)
function calls, not just recognized intrinsics.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103428 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AsmWriter.cpp
test/Feature/metadata.ll [new file with mode: 0644]

index fc845c14e88d15e4ca6c74cee45fc3cc6c924069..4e8938f7b7514cea325b8ca445a798576eb3d459 100644 (file)
@@ -677,11 +677,16 @@ void SlotTracker::processFunction() {
       if (!I->getType()->isVoidTy() && !I->hasName())
         CreateFunctionSlot(I);
       
-      // Intrinsics can directly use metadata.
-      if (isa<IntrinsicInst>(I))
-        for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
-          if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
-            CreateMetadataSlot(N);
+      // Intrinsics can directly use metadata.  We allow direct calls to any
+      // llvm.foo function here, because the target may not be linked into the
+      // optimizer.
+      if (const CallInst *CI = dyn_cast<CallInst>(I)) {
+        if (Function *F = CI->getCalledFunction())
+          if (F->getName().startswith("llvm."))
+            for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
+              if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
+                CreateMetadataSlot(N);
+      }
 
       // Process metadata attached with this instruction.
       I->getAllMetadata(MDForInst);
diff --git a/test/Feature/metadata.ll b/test/Feature/metadata.ll
new file mode 100644 (file)
index 0000000..3e2cd3c
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis
+; PR7105
+
+define void @foo() {
+  call void @llvm.zonk(metadata !1, i64 0, metadata !1)
+  ret void
+}
+
+declare void @llvm.zonk(metadata, i64, metadata) nounwind readnone
+
+!named = !{!0}
+!0 = metadata !{i8** null}
+!1 = metadata !{i8* null}