Add 'pedantic' mode to verifier rejecting syntactically valid, but 'bad' due to other...
authorAnton Korobeynikov <asl@math.spbu.ru>
Sun, 28 Oct 2007 22:50:32 +0000 (22:50 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sun, 28 Oct 2007 22:50:32 +0000 (22:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43424 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Verifier.cpp

index 000fa6bbb17ad3c1684f20b625622198b5bde287..1d35d65e61280e4d2ef47f90876028a74679eea2 100644 (file)
@@ -60,6 +60,7 @@
 #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
      Verifier : public FunctionPass, InstVisitor<Verifier> {
     static char ID; // Pass ID, replacement for typeid
@@ -806,10 +810,17 @@ void Verifier::visitCallInst(CallInst &CI) {
             "Call parameter type does not match function signature!",
             CI.getOperand(i+1), FTy->getParamType(i), &CI);
 
-  if (Function *F = CI.getCalledFunction())
+  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);
-
+  }
+  
   visitInstruction(CI);
 }