DI: Add Function::getSubprogram()
[oota-llvm.git] / lib / IR / Verifier.cpp
index c8aba14e8132e139f4dc4282d99dcb0cf3ba4b98..bcf8c0ffa1eea9e4eb13c38550aaa6d1fd0bfa11 100644 (file)
@@ -1779,8 +1779,20 @@ void Verifier::visitFunction(const Function &F) {
     }
 
     // Visit metadata attachments.
-    for (const auto &I : MDs)
+    for (const auto &I : MDs) {
+      // Verify that the attachment is legal.
+      switch (I.first) {
+      default:
+        break;
+      case LLVMContext::MD_dbg:
+        Assert(isa<DISubprogram>(I.second),
+               "function !dbg attachment must be a subprogram", &F, I.second);
+        break;
+      }
+
+      // Verify the metadata itself.
       visitMDNode(*I.second);
+    }
   }
 
   // If this function is actually an intrinsic, verify that it is only used in