]> granicus.if.org Git - llvm/commitdiff
Verifier: check that functions have at most a single !prof attachment.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 14 Jun 2016 23:13:15 +0000 (23:13 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 14 Jun 2016 23:13:15 +0000 (23:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272734 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Verifier.cpp
test/Verifier/metadata-function-prof.ll [new file with mode: 0644]

index 0395f5b36fef76162c25c6abb15299e3ffef7a0a..29550e2e733ad84e23571b23bacf9da54889b0ea 100644 (file)
@@ -1976,7 +1976,7 @@ void Verifier::visitFunction(const Function &F) {
              "blockaddress may not be used with the entry block!", Entry);
     }
 
-    unsigned NumDebugAttachments = 0;
+    unsigned NumDebugAttachments = 0, NumProfAttachments = 0;
     // Visit metadata attachments.
     for (const auto &I : MDs) {
       // Verify that the attachment is legal.
@@ -1990,6 +1990,11 @@ void Verifier::visitFunction(const Function &F) {
         AssertDI(isa<DISubprogram>(I.second),
                  "function !dbg attachment must be a subprogram", &F, I.second);
         break;
+      case LLVMContext::MD_prof:
+        ++NumProfAttachments;
+        Assert(NumProfAttachments == 1,
+               "function must have a single !prof attachment", &F, I.second);
+        break;
       }
 
       // Verify the metadata itself.
diff --git a/test/Verifier/metadata-function-prof.ll b/test/Verifier/metadata-function-prof.ll
new file mode 100644 (file)
index 0000000..ca0628f
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: not llvm-as %s -disable-output 2>&1 | FileCheck %s
+
+define void @foo() !prof !0 {
+  unreachable
+}
+
+; CHECK: function must have a single !prof attachment
+define void @foo2() !prof !0 !prof !0 {
+  unreachable
+}
+
+!0 = !{}