[cfe-commits] r53081 - in /cfe/trunk: Driver/AnalysisConsumer.cpp include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BugReporter.cpp lib/Analysis/DeadStores.cpp

Ted Kremenek kremenek at apple.com
Wed Jul 2 22:26:14 PDT 2008


Author: kremenek
Date: Thu Jul  3 00:26:14 2008
New Revision: 53081

URL: http://llvm.org/viewvc/llvm-project?rev=53081&view=rev
Log:
Have BugReporter::getCFG and BugReporter::getLiveVariables returns pointers instead of references, because they can both fail
on functions we cannot construct full CFGs for yet.

Modified:
    cfe/trunk/Driver/AnalysisConsumer.cpp
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/DeadStores.cpp

Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=53081&r1=53080&r2=53081&view=diff

==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Thu Jul  3 00:26:14 2008
@@ -123,9 +123,9 @@
     Decl* getCodeDecl() const { return D; }
     Stmt* getBody() const { return Body; }
     
-    virtual CFG& getCFG() {
+    virtual CFG* getCFG() {
       if (!cfg) cfg.reset(CFG::buildCFG(getBody()));
-      return *cfg.get();
+      return cfg.get();
     }
     
     virtual ParentMap& getParentMap() {
@@ -157,14 +157,17 @@
       return C.PD.get();      
     }
       
-    virtual LiveVariables& getLiveVariables() {
+    virtual LiveVariables* getLiveVariables() {
       if (!liveness) {
-        liveness.reset(new LiveVariables(getCFG()));
-        liveness->runOnCFG(getCFG());
-        liveness->runOnAllBlocks(getCFG(), 0, true);
+        CFG* c = getCFG();
+        if (!c) return 0;
+        
+        liveness.reset(new LiveVariables(*c));
+        liveness->runOnCFG(*c);
+        liveness->runOnAllBlocks(*c, 0, true);
       }
       
-      return *liveness.get();
+      return liveness.get();
     }
     
     bool shouldVisualize() const {
@@ -285,27 +288,32 @@
 //===----------------------------------------------------------------------===//
 
 static void ActionDeadStores(AnalysisManager& mgr) {
-  BugReporter BR(mgr);  
-  CheckDeadStores(mgr.getLiveVariables(), BR);
+  if (LiveVariables* L = mgr.getLiveVariables()) {
+    BugReporter BR(mgr);
+    CheckDeadStores(*L, BR);
+  }
 }
 
 static void ActionUninitVals(AnalysisManager& mgr) {
-  CheckUninitializedValues(mgr.getCFG(), mgr.getContext(),
-                           mgr.getDiagnostic());
+  if (CFG* c = mgr.getCFG())
+    CheckUninitializedValues(*c, mgr.getContext(), mgr.getDiagnostic());
 }
 
 
 static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf) {
   
+  
   llvm::OwningPtr<GRTransferFuncs> TF(tf);
+
+  // Construct the analysis engine.
+  LiveVariables* L = mgr.getLiveVariables();
+  if (!L) return;
   
   // Display progress.
   if (!mgr.shouldVisualize())
     mgr.DisplayFunction();
   
-  // Construct the analysis engine.
-  GRExprEngine Eng(mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext(),
-                   mgr.getLiveVariables());  
+  GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext(), *L);
   Eng.setTransferFunctions(tf);
   
   // Execute the worklist algorithm.
@@ -355,18 +363,24 @@
 }
 
 static void ActionLiveness(AnalysisManager& mgr) {
-  mgr.DisplayFunction();
-  mgr.getLiveVariables().dumpBlockLiveness(mgr.getSourceManager());
+  if (LiveVariables* L = mgr.getLiveVariables()) {
+    mgr.DisplayFunction();  
+    L->dumpBlockLiveness(mgr.getSourceManager());
+  }
 }
 
 static void ActionCFGDump(AnalysisManager& mgr) {
-  mgr.DisplayFunction();
-  mgr.getCFG().dump();
+  if (CFG* c = mgr.getCFG()) {
+    mgr.DisplayFunction();
+    c->dump();
+  }
 }
 
 static void ActionCFGView(AnalysisManager& mgr) {
-  mgr.DisplayFunction();
-  mgr.getCFG().viewCFG();  
+  if (CFG* c = mgr.getCFG()) {
+    mgr.DisplayFunction();
+    c->viewCFG();  
+  }
 }
 
 static void ActionCheckObjCDealloc(AnalysisManager& mgr) {

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=53081&r1=53080&r2=53081&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Thu Jul  3 00:26:14 2008
@@ -136,9 +136,9 @@
   virtual PathDiagnosticClient* getPathDiagnosticClient() = 0;  
   virtual ASTContext& getContext() = 0;
   virtual SourceManager& getSourceManager() = 0;
-  virtual CFG& getCFG() = 0;
+  virtual CFG* getCFG() = 0;
   virtual ParentMap& getParentMap() = 0;
-  virtual LiveVariables& getLiveVariables() = 0;
+  virtual LiveVariables* getLiveVariables() = 0;
 };
   
 class BugReporter {
@@ -173,7 +173,7 @@
     return D.getSourceManager();
   }
   
-  CFG& getCFG() {
+  CFG* getCFG() {
     return D.getCFG();
   }
   
@@ -181,7 +181,7 @@
     return D.getParentMap();  
   }
   
-  LiveVariables& getLiveVariables() {
+  LiveVariables* getLiveVariables() {
     return D.getLiveVariables();
   }
   

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=53081&r1=53080&r2=53081&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu Jul  3 00:26:14 2008
@@ -118,7 +118,7 @@
   Stmt *S = NULL;
   
   if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP))
-    if (BE->getBlock() == &BR.getCFG().getExit())
+    if (BE->getBlock() == &BR.getCFG()->getExit())
       S = GetLastStmt(EndNode);
   if (!S)
     S = GetStmt(ProgP);  

Modified: cfe/trunk/lib/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DeadStores.cpp?rev=53081&r1=53080&r2=53081&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/DeadStores.cpp Thu Jul  3 00:26:14 2008
@@ -153,7 +153,7 @@
   DiagCollector C(BT);  
 
   DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap());
-  L.runOnAllBlocks(BR.getCFG(), &A);
+  L.runOnAllBlocks(*BR.getCFG(), &A);
   
   // Emit the bug reports.
   





More information about the cfe-commits mailing list