]> granicus.if.org Git - clang/commitdiff
Patch by Zhongxing Xu!
authorTed Kremenek <kremenek@apple.com>
Tue, 19 Aug 2008 16:51:45 +0000 (16:51 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 19 Aug 2008 16:51:45 +0000 (16:51 +0000)
This patch extends BasicStoreManager::getInitialStore() to include code that symbolicates input variables.
It also removes redundant handling of ImplicitParamDecl, since it is a subclass of VarDecl.

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

include/clang/Analysis/PathSensitive/GRState.h
include/clang/Analysis/PathSensitive/Store.h
lib/Analysis/BasicStore.cpp
lib/Analysis/GRExprEngine.cpp
lib/Analysis/GRState.cpp

index 39d79bc3ae04a7278412652792c78c278a811c77..1944cca8fa61e63552ebae8fdb7070bee294c996 100644 (file)
@@ -270,7 +270,11 @@ private:
   /// TF - Object that represents a bundle of transfer functions
   ///  for manipulating and creating RVals.
   GRTransferFuncs* TF;
-  
+
+  /// Liveness - live-variables information of the ValueDecl* and block-level
+  /// Expr* in the CFG. Used to get initial store and prune out dead state.
+  LiveVariables& Liveness;
+
 private:
 
   Environment RemoveBlkExpr(const Environment& Env, Expr* E) {
@@ -284,7 +288,7 @@ private:
     
 public:  
   GRStateManager(ASTContext& Ctx, StoreManager* stmgr,
-                    llvm::BumpPtrAllocator& alloc, CFG& c
+                 llvm::BumpPtrAllocator& alloc, CFG& c, LiveVariables& L
   : EnvMgr(alloc),
     StMgr(stmgr),
     ISetFactory(alloc), 
@@ -292,7 +296,8 @@ public:
     BasicVals(Ctx, alloc),
     SymMgr(alloc),
     Alloc(alloc),
-    cfg(c) {}
+    cfg(c),
+    Liveness(L) {}
   
   ~GRStateManager();
 
@@ -301,7 +306,8 @@ public:
   BasicValueFactory& getBasicVals() { return BasicVals; }
   const BasicValueFactory& getBasicVals() const { return BasicVals; }
   SymbolManager& getSymbolManager() { return SymMgr; }
-  
+  LiveVariables& getLiveVariables() { return Liveness; }
+
   typedef StoreManager::DeadSymbolsTy DeadSymbolsTy;
   
   const GRState* RemoveDeadBindings(const GRState* St, Stmt* Loc, 
index 657ce8d954b06f4488286919b9fab6389c108ac9..acc3d8e8bb1c0fbb8a96a2f020d73336513327d4 100644 (file)
@@ -23,6 +23,7 @@
 namespace clang {
   
 typedef const void* Store;
+class GRStateManager;
 class LiveVariables;
 class Stmt;
   
@@ -36,7 +37,7 @@ public:
   virtual RVal GetRVal(Store St, LVal LV, QualType T = QualType()) = 0;
   virtual Store SetRVal(Store St, LVal LV, RVal V) = 0;
   virtual Store Remove(Store St, LVal LV) = 0;
-  virtual Store getInitialStore() = 0;
+  virtual Store getInitialStore(GRStateManager& StateMgr) = 0;
   
   virtual Store RemoveDeadBindings(Store store, Stmt* Loc,
                                    const LiveVariables& Live,
index 64a230975f0981010ce35db6a9b0344ea02b4c3e..15284567e67613fda98be2de9e79dc3543c780e1 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Analysis/PathSensitive/BasicStore.h"
+#include "clang/Analysis/PathSensitive/GRState.h"
 #include "llvm/ADT/ImmutableMap.h"
 #include "llvm/Support/Compiler.h"
 
@@ -32,9 +33,7 @@ public:
   virtual Store SetRVal(Store St, LVal LV, RVal V);  
   virtual Store Remove(Store St, LVal LV);
 
-  virtual Store getInitialStore() {
-    return VBFactory.GetEmptyMap().getRoot();
-  }
+  virtual Store getInitialStore(GRStateManager& StateMgr);
   
   virtual Store RemoveDeadBindings(Store store, Stmt* Loc,
                                    const LiveVariables& Live,
@@ -200,3 +199,38 @@ Store BasicStoreManager::RemoveDeadBindings(Store store,
 
   return store;
 }
+
+Store BasicStoreManager::getInitialStore(GRStateManager& StateMgr) {
+  // The LiveVariables information already has a compilation of all VarDecls
+  // used in the function.  Iterate through this set, and "symbolicate"
+  // any VarDecl whose value originally comes from outside the function.
+
+  typedef LiveVariables::AnalysisDataTy LVDataTy;
+  LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData();
+
+  Store St = VBFactory.GetEmptyMap().getRoot();
+
+  for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
+    ScopedDecl* SD = const_cast<ScopedDecl*>(I->first);
+
+    if (VarDecl* VD = dyn_cast<VarDecl>(SD)) {
+      // Punt on static variables for now.
+      if (VD->getStorageClass() == VarDecl::Static)
+        continue;
+
+      // Only handle pointers and integers for now.
+      QualType T = VD->getType();
+      if (LVal::IsLValType(T) || T->isIntegerType()) {
+        // Initialize globals and parameters to symbolic values.
+        // Initialize local variables to undefined.
+        RVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
+                  isa<ImplicitParamDecl>(VD))
+                 ? RVal::GetSymbolValue(StateMgr.getSymbolManager(), VD)
+                 : UndefinedVal();
+
+        St = SetRVal(St, lval::DeclVal(VD), X);
+      }
+    }
+  }
+  return St;
+}
index 18c5a5825ec579cc5bb7602c1241cb982916899d..7433509c85e80f067c814cd3c60a7c28e56b7f6f 100644 (file)
@@ -121,7 +121,7 @@ GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx,
     Liveness(L),
     Builder(NULL),
     StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator()),
-             G.getAllocator(), G.getCFG()),
+             G.getAllocator(), G.getCFG(), L),
     SymMgr(StateMgr.getSymbolManager()),
     CurrentStmt(NULL),
   NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL),
@@ -189,47 +189,7 @@ void GRExprEngine::AddCheck(GRSimpleAPICheck* A, Stmt::StmtClass C) {
 }
 
 const GRState* GRExprEngine::getInitialState() {
-
-  // The LiveVariables information already has a compilation of all VarDecls
-  // used in the function.  Iterate through this set, and "symbolicate"
-  // any VarDecl whose value originally comes from outside the function.
-  
-  typedef LiveVariables::AnalysisDataTy LVDataTy;
-  LVDataTy& D = Liveness.getAnalysisData();
-  
-  GRState StateImpl = *StateMgr.getInitialState();
-  
-  for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
-    
-    ScopedDecl *SD = const_cast<ScopedDecl*>(I->first);
-    if (VarDecl* VD = dyn_cast<VarDecl>(SD)) {
-      // Punt on static variables for now.
-      if (VD->getStorageClass() ==  VarDecl::Static)
-        continue;
-      
-      // Only handle pointers and integers for now.
-      QualType T = VD->getType();      
-      if (!(LVal::IsLValType(T) || T->isIntegerType()))
-        continue;
-      
-      // Initialize globals and parameters to symbolic values.
-      // Initialize local variables to undefined.
-      RVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
-                isa<ImplicitParamDecl>(VD))
-             ? RVal::GetSymbolValue(SymMgr, VD)
-             : UndefinedVal();
-      
-      StateMgr.SetRVal(StateImpl, lval::DeclVal(VD), X);
-      
-    } else if (ImplicitParamDecl *IPD = dyn_cast<ImplicitParamDecl>(SD)) {
-        RVal X = RVal::GetSymbolValue(SymMgr, IPD);
-      StateMgr.SetRVal(StateImpl, lval::DeclVal(IPD), X);
-    }
-      
-
-  }
-  
-  return StateMgr.getPersistentState(StateImpl);
+  return StateMgr.getInitialState();
 }
 
 //===----------------------------------------------------------------------===//
index cd81c57f90b931fa553a2aff1921fe15aa6b18f3..e4022a2663bee82f805d05d214bd1ffb3aa4697a 100644 (file)
@@ -211,9 +211,10 @@ const GRState* GRStateManager::AddEQ(const GRState* St, SymbolID sym,
 
 const GRState* GRStateManager::getInitialState() {
 
-  GRState StateImpl(EnvMgr.getInitialEnvironment(), StMgr->getInitialStore(),
+  GRState StateImpl(EnvMgr.getInitialEnvironment(), 
+                    StMgr->getInitialStore(*this),
                     GDMFactory.GetEmptyMap());
-  
+
   return getPersistentState(StateImpl);
 }