[cfe-commits] r48322 - in /cfe/trunk: AST/CFG.cpp Driver/ASTConsumers.cpp

Ted Kremenek kremenek at apple.com
Wed Mar 12 20:04:24 PDT 2008


Author: kremenek
Date: Wed Mar 12 22:04:22 2008
New Revision: 48322

URL: http://llvm.org/viewvc/llvm-project?rev=48322&view=rev
Log:
Added bandaid support in CFG construction for ObjCForEachStmt and ObjCAtTryStmt:
we gracefully back out and return NULL for the CFG, allowing clients to skip
analyzing functions with these CFGs. We will add support later.

Modified base ASTConsumer "CFGVisitor" to detect when a CFG is not constructed
and to emit a warning.

Modified:
    cfe/trunk/AST/CFG.cpp
    cfe/trunk/Driver/ASTConsumers.cpp

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

==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Wed Mar 12 22:04:22 2008
@@ -113,6 +113,18 @@
   CFGBlock* VisitDefaultStmt(DefaultStmt* D);
   CFGBlock* VisitIndirectGotoStmt(IndirectGotoStmt* I);
   
+  // FIXME: Add support for ObjC-specific control-flow structures.
+  
+  CFGBlock* VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
+    badCFG = true;
+    return Block;
+  }
+  
+  CFGBlock* VisitObjCAtTryStmt(ObjCAtTryStmt* S) {
+    badCFG = true;
+    return Block;
+  }
+  
 private:
   CFGBlock* createBlock(bool add_successor = true);
   CFGBlock* addStmt(Stmt* S);
@@ -122,6 +134,7 @@
   CFGBlock* WalkAST_VisitStmtExpr(StmtExpr* S);
   void FinishBlock(CFGBlock* B);
   
+  bool badCFG;
 };
     
 /// BuildCFG - Constructs a CFG from an AST (a Stmt*).  The AST can
@@ -133,6 +146,8 @@
   assert (cfg);
   if (!Statement) return NULL;
 
+  badCFG = false;
+  
   // Create an empty block that will serve as the exit block for the CFG.
   // Since this is the first block added to the CFG, it will be implicitly
   // registered as the exit block.
@@ -186,6 +201,12 @@
   // Create an empty entry block that has no predecessors.    
   cfg->setEntry(createBlock());
     
+  if (badCFG) {
+    delete cfg;
+    cfg = NULL;
+    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;

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=48322&r1=48321&r2=48322&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Mar 12 22:04:22 2008
@@ -482,8 +482,13 @@
   }
     
   CFG *C = CFG::buildCFG(FD->getBody());
-  VisitCFG(*C, *FD);
-  delete C;
+  
+  if (C) {  
+    VisitCFG(*C, *FD);
+    delete C;
+  }
+  else
+    llvm::cerr << "warning: CFG could not be constructed.\n";
 }
 
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list