#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
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
+ AU.addRequiredID(PreVerifyID);
if (RealPass)
AU.addRequired<DominatorTree>();
}
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);
}