]> granicus.if.org Git - clang/commitdiff
Have IdempotentOperationsChecker pull its CFGStmtMap from AnalysisContext.
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 01:51:53 +0000 (01:51 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 01:51:53 +0000 (01:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126288 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/AnalysisContext.h
include/clang/Sema/AnalysisBasedWarnings.h
lib/Analysis/AnalysisContext.cpp
lib/Sema/AnalysisBasedWarnings.cpp
lib/Sema/Sema.cpp
lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp

index 2ecbfdc6bf02dee4e94f28904619bf2c11f31955..69446eb814f676b235278e6f0bbb7352059c3232 100644 (file)
@@ -29,6 +29,7 @@ class Decl;
 class Stmt;
 class CFG;
 class CFGBlock;
+class CFGStmtMap;
 class LiveVariables;
 class ParentMap;
 class PseudoConstantAnalysis;
@@ -48,6 +49,7 @@ class AnalysisContext {
 
   // AnalysisContext owns the following data.
   CFG *cfg, *completeCFG;
+  CFGStmtMap *cfgStmtMap;
   bool builtCFG, builtCompleteCFG;
   LiveVariables *liveness;
   LiveVariables *relaxedLiveness;
@@ -65,7 +67,7 @@ public:
                   bool addehedges = false,
                   bool addImplicitDtors = false,
                   bool addInitializers = false)
-    : D(d), TU(tu), cfg(0), completeCFG(0),
+    : D(d), TU(tu), cfg(0), completeCFG(0), cfgStmtMap(0),
       builtCFG(false), builtCompleteCFG(false),
       liveness(0), relaxedLiveness(0), PM(0), PCA(0),
       ReferencedBlockVars(0), UseUnoptimizedCFG(useUnoptimizedCFG),
@@ -91,6 +93,8 @@ public:
 
   Stmt *getBody();
   CFG *getCFG();
+  
+  CFGStmtMap *getCFGStmtMap();
 
   /// Return a version of the CFG without any edges pruned.
   CFG *getUnoptimizedCFG();
index 192be4db2f6e21f4ba9718c1cc72014ea1df5d77..8b389b169b3ce689c2e83c0865e4d82a9b41dedd 100644 (file)
@@ -25,6 +25,9 @@ class FunctionDecl;
 class ObjCMethodDecl;
 class QualType;
 class Sema;
+namespace sema {
+  class FunctionScopeInfo;
+}
 
 namespace sema {
 
@@ -51,7 +54,8 @@ private:
 public:
   AnalysisBasedWarnings(Sema &s);
 
-  void IssueWarnings(Policy P, const Decl *D, const BlockExpr *blkExpr);
+  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
+                     const Decl *D, const BlockExpr *blkExpr);
 
   Policy getDefaultPolicy() { return DefaultPolicy; }
 };
index 5233d3b8f9f89e02ae94cc2cc684b997d6307ba0..a982a5c5be93e0b1bea4c0f807be4f739046050f 100644 (file)
@@ -21,6 +21,7 @@
 #include "clang/Analysis/Analyses/PseudoConstantAnalysis.h"
 #include "clang/Analysis/AnalysisContext.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Analysis/CFGStmtMap.h"
 #include "clang/Analysis/Support/BumpVector.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -86,6 +87,19 @@ CFG *AnalysisContext::getUnoptimizedCFG() {
   return completeCFG;
 }
 
+CFGStmtMap *AnalysisContext::getCFGStmtMap() {
+  if (cfgStmtMap)
+    return cfgStmtMap;
+  
+  if (CFG *c = getCFG()) {
+    cfgStmtMap = CFGStmtMap::Build(c, &getParentMap());
+    return cfgStmtMap;
+  }
+    
+  return 0;
+}
+  
+
 void AnalysisContext::dumpCFG() {
     getCFG()->dump(getASTContext().getLangOptions());
 }
@@ -346,6 +360,7 @@ AnalysisContext::getReferencedBlockVars(const BlockDecl *BD) {
 AnalysisContext::~AnalysisContext() {
   delete cfg;
   delete completeCFG;
+  delete cfgStmtMap;
   delete liveness;
   delete relaxedLiveness;
   delete PM;
index 7a1aceb4c686c0deb034431cd8e0753b32554620..adfa690a643cc4008e66dd1894f0aeb75a494383 100644 (file)
@@ -480,6 +480,7 @@ clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s) : S(s) {
 
 void clang::sema::
 AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
+                                     sema::FunctionScopeInfo *fscope,
                                      const Decl *D, const BlockExpr *blkExpr) {
 
   // We avoid doing analysis-based warnings when there are errors for
index 1920f1e6fc8fd426942c6f7e237b1a8a02e404f1..0827597abdfbc8487c4fe9daf5f018ad5b55a357 100644 (file)
@@ -638,7 +638,7 @@ void Sema::PopFunctionOrBlockScope(const AnalysisBasedWarnings::Policy *WP,
   
   // Issue any analysis-based warnings.
   if (WP && D)
-    AnalysisWarnings.IssueWarnings(*WP, D, blkExpr);
+    AnalysisWarnings.IssueWarnings(*WP, Scope, D, blkExpr);
 
   if (FunctionScopes.back() != Scope)
     delete Scope;
index f49b125a60a2987425d1959db2a74cacae241073..0d2ccb955f2037ff9a9eee151b4c2f4556a4aaa9 100644 (file)
@@ -397,16 +397,13 @@ void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G,
     // If the analyzer did not finish, check to see if we can still emit this
     // warning
     if (Eng.hasWorkRemaining()) {
-      const CFGStmtMap *CBM = CFGStmtMap::Build(AC->getCFG(),
-                                                &AC->getParentMap());
+      const CFGStmtMap *CBM = AC->getCFGStmtMap();
 
       // If we can trace back
       if (!pathWasCompletelyAnalyzed(AC->getCFG(),
                                      CBM->getBlock(B), CBM,
                                      Eng.getCoreEngine()))
         continue;
-
-      delete CBM;
     }
 
     // Select the error message and SourceRanges to report.