diff options
| author | Owen Anderson <resistor@mac.com> | 2007-10-31 21:04:18 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2007-10-31 21:04:18 +0000 |
| commit | 9396c3950188bb622091f3e520eb9737d85f251f (patch) | |
| tree | bc3f8bcc1f08465ed89975d8a211704618ca641a /llvm/lib/VMCore/Verifier.cpp | |
| parent | cc4c2930ae7a021580d3ca7fc887817aaf826c7e (diff) | |
| download | bcm5719-llvm-9396c3950188bb622091f3e520eb9737d85f251f.tar.gz bcm5719-llvm-9396c3950188bb622091f3e520eb9737d85f251f.zip | |
Add a preverifier pass to check that every basic block ends in a terminator, so that we don't segfault when verifying invalid code.
llvm-svn: 43578
Diffstat (limited to 'llvm/lib/VMCore/Verifier.cpp')
| -rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 68c30bbc638..afb90d44566 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -71,7 +71,25 @@ namespace { // Anonymous namespace for class cl::opt<bool> Pedantic("verify-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) { } + + bool runOnFunction(Function &F) { + for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) + assert(I->back().isTerminator() + && "Block does not end with a terminator?"); + + 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 +179,7 @@ namespace { // Anonymous namespace for class virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); + AU.addRequiredID(PreVerifyID); if (RealPass) AU.addRequired<DominatorTree>(); } |

