Don't barf on empty basic blocks. Do not rely on assert

doing something - this needs to work for release builds
too.  I chose to just abort rather than following the
fancy logic of abortIfBroken, because (1) it is a pain
to do otherwise, and (2) nothing is going to work if the
module is this broken.

llvm-svn: 43611
This commit is contained in:
Duncan Sands 2007-11-01 10:50:26 +00:00
parent 87f460f8ba
commit e0e774b6fd
1 changed files with 21 additions and 9 deletions

View File

@ -69,22 +69,34 @@ using namespace llvm;
namespace { // Anonymous namespace for class
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) {
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;
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