]> granicus.if.org Git - clang/commitdiff
When analyzing a function, eagerly create symbolic values for all
authorTed Kremenek <kremenek@apple.com>
Wed, 27 Feb 2008 06:47:26 +0000 (06:47 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 27 Feb 2008 06:47:26 +0000 (06:47 +0000)
globals/parameters at the beginning of the analysis.

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

Analysis/GRExprEngine.cpp
Analysis/ValueState.cpp
include/clang/Analysis/PathSensitive/GRExprEngine.h
include/clang/Analysis/PathSensitive/ValueState.h

index d2200bfa0fef04bdc3969b4346055cb4cd64c50f..758e038865fd88e63a182e36f1a3b097e31a2f30 100644 (file)
@@ -26,6 +26,30 @@ using llvm::dyn_cast;
 using llvm::cast;
 using llvm::APSInt;
 
+GRExprEngine::StateTy 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();
+  
+  ValueStateImpl StateImpl = *StateMgr.getInitialState().getImpl();
+  
+  for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
+    
+    VarDecl* VD = cast<VarDecl>(const_cast<ScopedDecl*>(I->first));
+    
+    if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
+      RVal X = RVal::GetSymbolValue(SymMgr, VD);
+      StateMgr.BindVar(StateImpl, VD, X);
+    }
+  }
+  
+  return StateMgr.getPersistentState(StateImpl);
+}      
+      
 GRExprEngine::StateTy
 GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) {
 
@@ -455,22 +479,6 @@ void GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred,
 
 void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){
 
-  if (VarDecl* VD = dyn_cast<VarDecl>(D->getDecl()))
-    if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
-
-      StateTy StOld = Pred->getState();
-      StateTy St = Symbolicate(StOld, VD);
-
-      if (!(St == StOld)) {
-        if (D != CurrentStmt)
-          Nodify(Dst, D, Pred, St);
-        else
-          Nodify(Dst, D, Pred, SetRVal(St, D, GetRVal(St, D)));
-        
-        return;
-      }
-    }
-  
   if (D != CurrentStmt) {
     Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
     return;
@@ -884,20 +892,7 @@ void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) {
   
   Ex = Ex->IgnoreParens();
   
-  if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(Ex)) {
-    
-    if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()))
-      if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
-        
-        StateTy StOld = Pred->getState();
-        StateTy St = Symbolicate(StOld, VD);
-        
-        if (!(St == StOld)) {
-          Nodify(Dst, Ex, Pred, St);
-          return;
-        }
-      }
-    
+  if (isa<DeclRefExpr>(Ex)) {
     Dst.Add(Pred);
     return;
   }
index cdd616fb147a96dc1265b4e13d66c90d8d53cb35..b90e265af24612f7ef08ad8d4fa6f1df34b0efe3 100644 (file)
@@ -437,10 +437,14 @@ ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
   }
 }
 
+void ValueStateManager::BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V) {
+  StImpl.VarBindings = VBFactory.Add(StImpl.VarBindings, D, V);
+}
+
 ValueState ValueStateManager::BindVar(ValueState St, VarDecl* D, RVal V) {
   
   // Create a new state with the old binding removed.
-  ValueStateImpl NewSt = *St;
+  ValueStateImpl NewSt = *St;  
   NewSt.VarBindings = VBFactory.Add(NewSt.VarBindings, D, V);
   
   // Get the persistent copy.
index 16fd977105005d372ba6e1053cdc1654cf5318d5..13abf53cb39f0a3c85fad544e125e2ce329d13a6 100644 (file)
@@ -150,7 +150,7 @@ public:
   
   /// getInitialState - Return the initial state used for the root vertex
   ///  in the ExplodedGraph.
-  StateTy getInitialState() { return StateMgr.getInitialState(); }
+  StateTy getInitialState();
   
   bool isUninitControlFlow(const NodeTy* N) const {
     return N->isSink() && UninitBranches.count(const_cast<NodeTy*>(N)) != 0;
@@ -252,15 +252,6 @@ protected:
     return StateMgr.GetLVal(St, Ex);
   }
   
-  StateTy Symbolicate(StateTy St, VarDecl* VD) {
-    lval::DeclVal X(VD);
-    
-    if (GetRVal(St, X).isUnknown()) {
-      return SetRVal(St, lval::DeclVal(VD), RVal::GetSymbolValue(SymMgr, VD));
-    }
-    else return St;
-  }
-  
   inline NonLVal MakeConstantVal(uint64_t X, Expr* Ex) {
     return NonLVal::MakeVal(ValMgr, X, Ex->getType(), Ex->getLocStart());
   }
index 5458ab86e59ca4ee09fae30af9329a642b98ed6f..c3e913ab703f2701d47e9eb3d55a7da77e112460 100644 (file)
@@ -266,6 +266,7 @@ public:
   
   RVal GetBlkExprRVal(ValueState St, Expr* Ex);
   
+  void BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V);
   ValueState getPersistentState(const ValueStateImpl& Impl);
   
   ValueState AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V);