Fixed two bugs in CFG construction:

BUG 1) 

CFG failed to build for empty functions, or functions containing only
NullStmts or empty compound statements.

We now handle such cases, although now we cannot test for CFG
construction failure by asserting that the last block constructed is
not NULL (since it now may be).

BUG 2)

CFG construction segfaulted on some cases when walking the AST and not
taking into account that some children of a statement may be NULL.

llvm-svn: 42370
This commit is contained in:
Ted Kremenek 2007-09-26 21:23:31 +00:00
parent b805d35d16
commit 5c50fd1add
1 changed files with 11 additions and 14 deletions

View File

@ -173,21 +173,18 @@ CFG* CFGBuilder::buildCFG(Stmt* Statement) {
B->addSuccessor(LI->second);
}
// Create an empty entry block that has no predecessors.
Succ = B;
cfg->setEntry(createBlock());
}
// Create an empty entry block that has no predecessors.
cfg->setEntry(createBlock());
// NULL out cfg so that repeated calls to the builder will fail and that
// the ownership of the constructed CFG is passed to the caller.
CFG* t = cfg;
cfg = NULL;
return t;
}
else {
assert (false && "CFG construction failed.");
return NULL;
}
// NULL out cfg so that repeated calls to the builder will fail and that
// the ownership of the constructed CFG is passed to the caller.
CFG* t = cfg;
cfg = NULL;
return t;
}
/// createBlock - Used to lazily create blocks that are connected
@ -354,7 +351,7 @@ CFGBlock* CFGBuilder::WalkAST_VisitChildren(Stmt* S) {
CFGBlock* B = Block;
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end() ;
I != E; ++I)
B = WalkAST(*I);
if (*I) B = WalkAST(*I);
return B;
}