Don't barf on empty basic blocks. Do not rely on assert
[oota-llvm.git] / lib / VMCore / Verifier.cpp
index 1d35d65e61280e4d2ef47f90876028a74679eea2..dea94088fa29fb7bdcec1b11b47265003234a958 100644 (file)
@@ -60,7 +60,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include <algorithm>
 #include <sstream>
 using namespace llvm;
 
 namespace {  // Anonymous namespace for class
-  cl::opt<bool>
-  Pedantic("pedantic",
-           cl::desc("Reject code with undefined behaviour"));
-    
+  struct VISIBILITY_HIDDEN PreVerifier : public FunctionPass {
+    static char ID; // Pass ID, replacement for typeid
+
+    PreVerifier() : FunctionPass((intptr_t)&ID) { }
+
+    // Check that the prerequisites for successful DominatorTree construction
+    // are satisfied.
+    bool runOnFunction(Function &F) {
+      bool Broken = false;
+
+      for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+        if (I->empty() || !I->back().isTerminator()) {
+          cerr << "Basic Block does not have terminator!\n";
+          WriteAsOperand(*cerr, I, true);
+          cerr << "\n";
+          Broken = true;
+        }
+      }
+
+      if (Broken)
+        abort();
+
+      return false;
+    }
+  };
+
+  char PreVerifier::ID = 0;
+  RegisterPass<PreVerifier> PreVer("preverify", "Preliminary module verification");
+  const PassInfo *PreVerifyID = PreVer.getPassInfo();
+
   struct VISIBILITY_HIDDEN
      Verifier : public FunctionPass, InstVisitor<Verifier> {
     static char ID; // Pass ID, replacement for typeid
@@ -161,6 +186,7 @@ namespace {  // Anonymous namespace for class
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesAll();
+      AU.addRequiredID(PreVerifyID);
       if (RealPass)
         AU.addRequired<DominatorTree>();
     }
@@ -811,12 +837,6 @@ void Verifier::visitCallInst(CallInst &CI) {
             CI.getOperand(i+1), FTy->getParamType(i), &CI);
 
   if (Function *F = CI.getCalledFunction()) {
-    if (Pedantic) {
-      // Verify that calling convention of Function and CallInst match
-      Assert1(F->getCallingConv() == CI.getCallingConv(),
-              "Call uses different calling convention than function", &CI);
-    }
-    
     if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID())
       visitIntrinsicFunctionCall(ID, CI);
   }