[llvm] r272734 - Verifier: check that functions have at most a single !prof attachment.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 16:13:15 PDT 2016


Author: pcc
Date: Tue Jun 14 18:13:15 2016
New Revision: 272734

URL: http://llvm.org/viewvc/llvm-project?rev=272734&view=rev
Log:
Verifier: check that functions have at most a single !prof attachment.

Added:
    llvm/trunk/test/Verifier/metadata-function-prof.ll
Modified:
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=272734&r1=272733&r2=272734&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Tue Jun 14 18:13:15 2016
@@ -1976,7 +1976,7 @@ void Verifier::visitFunction(const Funct
              "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 Funct
         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.

Added: llvm/trunk/test/Verifier/metadata-function-prof.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/metadata-function-prof.ll?rev=272734&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/metadata-function-prof.ll (added)
+++ llvm/trunk/test/Verifier/metadata-function-prof.ll Tue Jun 14 18:13:15 2016
@@ -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 = !{}




More information about the llvm-commits mailing list