]> granicus.if.org Git - clang/commitdiff
Have BugReporter::getCFG and BugReporter::getLiveVariables returns pointers instead...
authorTed Kremenek <kremenek@apple.com>
Thu, 3 Jul 2008 05:26:14 +0000 (05:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 3 Jul 2008 05:26:14 +0000 (05:26 +0000)
on functions we cannot construct full CFGs for yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53081 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/AnalysisConsumer.cpp
include/clang/Analysis/PathSensitive/BugReporter.h
lib/Analysis/BugReporter.cpp
lib/Analysis/DeadStores.cpp

index c557b80c7ee86c8f883ec5cceaba6030f25d6ddb..1dc2fac4f848b699d93159466cb1ad789e100402 100644 (file)
@@ -123,9 +123,9 @@ namespace {
     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 @@ namespace {
       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 @@ void AnalysisConsumer::HandleCode(Decl* D, Stmt* Body, Actions actions) {
 //===----------------------------------------------------------------------===//
 
 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 ActionSimpleChecks(AnalysisManager& mgr) {
 }
 
 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) {
index f608da0c2e5cac223b9b1c8ac1a68f20a83eb203..d1c430fc961d785b01793ecac7a2ec2872e6a799 100644 (file)
@@ -136,9 +136,9 @@ public:
   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 @@ public:
     return D.getSourceManager();
   }
   
-  CFG& getCFG() {
+  CFG* getCFG() {
     return D.getCFG();
   }
   
@@ -181,7 +181,7 @@ public:
     return D.getParentMap();  
   }
   
-  LiveVariables& getLiveVariables() {
+  LiveVariables* getLiveVariables() {
     return D.getLiveVariables();
   }
   
index 1741e7dc9b55f4a7d674e0ddc68e51eb5e48e0b0..fba31f81af3aa77f52976a78bc64d9cc42552bcb 100644 (file)
@@ -118,7 +118,7 @@ Stmt* BugReport::getStmt(BugReporter& BR) const {
   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);  
index 02198b2906672f46f8eb22aacd72400f250e257a..ded0ed0d89ffd45acc9da471b1e1773fc9826e05 100644 (file)
@@ -153,7 +153,7 @@ void clang::CheckDeadStores(LiveVariables& L, BugReporter& BR) {
   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.