]> granicus.if.org Git - clang/commitdiff
Add an option to make 'RemoveDeadBindings' a configurable behavior. This enables
authorZhongxing Xu <xuzhongxing@gmail.com>
Mon, 22 Dec 2008 01:52:37 +0000 (01:52 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Mon, 22 Dec 2008 01:52:37 +0000 (01:52 +0000)
us to measure the effect of this optimization.

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

Driver/AnalysisConsumer.cpp
include/clang/Analysis/PathSensitive/GRExprEngine.h
lib/Analysis/GRExprEngine.cpp
test/Analysis/null-deref-ps.c

index 3cffc20ea0b421df94f5b8ca13793bacd51b768b..1ada515c10e017b802b1d2c20d855b7b0293f73e 100644 (file)
@@ -31,6 +31,7 @@
 #include "clang/Analysis/LocalCheckers.h"
 #include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
 #include "clang/Analysis/PathSensitive/GRExprEngine.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
 using namespace clang;
 
 static ExplodedNodeImpl::Auditor* CreateUbiViz();
+
+// Analyzer options.
+static llvm::cl::opt<bool>
+PurgeDead("analyzer-purge-dead",
+          llvm::cl::init(true),
+          llvm::cl::desc("Remove dead symbols, bindings, and constraints before"
+                         " processing a statement."));
   
 //===----------------------------------------------------------------------===//
 // Basic type definitions.
@@ -85,7 +93,7 @@ namespace {
                      const std::string& fname,
                      const std::string& htmldir,
                      AnalysisStores sm, AnalysisDiagClients dc,
-                     bool visgraphviz, bool visubi, bool trim, bool analyzeAll) 
+                     bool visgraphviz, bool visubi, bool trim, bool analyzeAll)
       : VisGraphviz(visgraphviz), VisUbigraph(visubi), TrimGraph(trim),
         LOpts(lopts), Diags(diags),
         Ctx(0), PP(pp), PPF(ppf),
@@ -136,12 +144,12 @@ namespace {
 
   public:
     AnalysisManager(AnalysisConsumer& c, Decl* d, Stmt* b) 
-    : D(d), Body(b), TU(0), AScope(ScopeDecl), C(c), DisplayedFunction(false) {
+      : D(d), Body(b), TU(0), AScope(ScopeDecl), C(c), DisplayedFunction(false){
       setManagerCreators();
     }
     
     AnalysisManager(AnalysisConsumer& c, TranslationUnit* tu) 
-    : D(0), Body(0), TU(tu), AScope(ScopeTU), C(c), DisplayedFunction(false) {
+      : D(0), Body(0), TU(tu), AScope(ScopeTU), C(c), DisplayedFunction(false) {
       setManagerCreators();
     }
     
@@ -403,6 +411,7 @@ static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf,
   if (!L) return;
 
   GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext(), *L,
+                   PurgeDead,
                    mgr.getStoreManagerCreator(), 
                    mgr.getConstraintManagerCreator());
 
index a9149dbb9715096e52daef71a29014b38e8c40a8..f7f228cfcca2481cb30547047f6a0bbed9996e8a 100644 (file)
@@ -92,6 +92,9 @@ protected:
   Selector RaiseSel;
   
   llvm::OwningPtr<GRSimpleAPICheck> BatchAuditor;
+
+  /// PurgeDead - Remove dead bindings before processing a statement.
+  bool PurgeDead;
   
 public:
   typedef llvm::SmallPtrSet<NodeTy*,2> ErrorNodes;  
@@ -178,6 +181,7 @@ public:
   
 public:
   GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, LiveVariables& L,
+               bool purgeDead,
                StoreManagerCreator SMC = CreateBasicStoreManager,
                ConstraintManagerCreator CMC = CreateBasicConstraintManager);
   
index 424229019ec282d0b95a072385d6de32772fae5d..0b9ae6088b50b7fb8014faf10311b1731f6450ed 100644 (file)
@@ -115,12 +115,13 @@ static inline Selector GetNullarySelector(const char* name, ASTContext& Ctx) {
 
 
 GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx,
-                           LiveVariables& L,
+                           LiveVariables& L, bool purgeDead,
                            StoreManagerCreator SMC,
                            ConstraintManagerCreator CMC)
   : CoreEngine(cfg, CD, Ctx, *this), 
     G(CoreEngine.getGraph()),
     Liveness(L),
+    PurgeDead(purgeDead),
     Builder(NULL),
     StateMgr(G.getContext(), SMC, CMC, G.getAllocator(), cfg, CD, L),
     SymMgr(StateMgr.getSymbolManager()),
@@ -211,8 +212,12 @@ void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) {
     Builder->setAuditor(BatchAuditor.get());
   
   // Create the cleaned state.  
-  CleanedState = StateMgr.RemoveDeadBindings(EntryNode->getState(), CurrentStmt,
-                                             Liveness, DeadSymbols);
+  if (PurgeDead)
+    CleanedState = StateMgr.RemoveDeadBindings(EntryNode->getState(), 
+                                               CurrentStmt,
+                                               Liveness, DeadSymbols);
+  else
+    CleanedState = EntryNode->getState();
   
   // Process any special transfer function for dead symbols.
   NodeSet Tmp;
index 8322be18afdf306f176d47756430e6bf23e85aac..028eaabc4925b3293b3ac9813cdac5a9ef669667 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: clang -std=gnu99 -checker-simple -verify %s
-// DISABLE: clang -std=gnu99 -checker-simple -analyzer-store-region -verify %s
+// RUN: clang -std=gnu99 -checker-simple -verify %s &&
+// RUN: clang -std=gnu99 -checker-simple -analyzer-store-region -analyzer-purge-dead=false -verify %s
 
 #include<stdint.h>
 #include <assert.h>