From: Ted Kremenek Date: Wed, 26 Sep 2007 21:23:31 +0000 (+0000) Subject: Fixed two bugs in CFG construction: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=322f58d3830da13b419646c071e3ab801518a09c;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42370 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/CFG.cpp b/AST/CFG.cpp index 42b27d23ab..d91f9c3c57 100644 --- a/AST/CFG.cpp +++ b/AST/CFG.cpp @@ -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()); - - // 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; } + + // 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; } /// 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; }