[cfe-commits] r42370 - /cfe/trunk/AST/CFG.cpp

Ted Kremenek kremenek at apple.com
Wed Sep 26 14:23:31 PDT 2007


Author: kremenek
Date: Wed Sep 26 16:23:31 2007
New Revision: 42370

URL: http://llvm.org/viewvc/llvm-project?rev=42370&view=rev
Log:
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.

Modified:
    cfe/trunk/AST/CFG.cpp

Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=42370&r1=42369&r2=42370&view=diff

==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Wed Sep 26 16:23:31 2007
@@ -173,21 +173,18 @@
         
         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* 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;
 }





More information about the cfe-commits mailing list