]> granicus.if.org Git - clang/commitdiff
Fixed two bugs in CFG construction:
authorTed Kremenek <kremenek@apple.com>
Wed, 26 Sep 2007 21:23:31 +0000 (21:23 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 26 Sep 2007 21:23:31 +0000 (21:23 +0000)
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

AST/CFG.cpp

index 42b27d23ab36badaaef7b717feb9c39795fe3d2c..d91f9c3c57ff3279fb23a3969a457dab93448a4b 100644 (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());
-    
-    // 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;
 }