[cfe-commits] r59152 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Environment.h include/clang/Analysis/PathSensitive/GRState.h lib/Analysis/Environment.cpp lib/Analysis/GRState.cpp

Ted Kremenek kremenek at apple.com
Wed Nov 12 11:21:38 PST 2008


Author: kremenek
Date: Wed Nov 12 13:21:30 2008
New Revision: 59152

URL: http://llvm.org/viewvc/llvm-project?rev=59152&view=rev
Log:
GRStateRef:
- Rename SetSVal to BindLoc
- Add BindDecl
- Add BindExpr

GRState:
- Environment now binds to Stmt* instead of Expr*.  This is needed for processing ObjCForCollectionStmt (essentially the declaration of the the 'element' variable can have an SVal attached to it).
- BindDecl no longer accepts Expr* for the initialization value; use SVal* instead.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
    cfe/trunk/lib/Analysis/Environment.cpp
    cfe/trunk/lib/Analysis/GRState.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h?rev=59152&r1=59151&r2=59152&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h Wed Nov 12 13:21:30 2008
@@ -1,4 +1,4 @@
-//== Environment.h - Map from Expr* to Locations/Values ---------*- C++ -*--==//
+//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -36,7 +36,7 @@
   friend class EnvironmentManager;
   
   // Type definitions.
-  typedef llvm::ImmutableMap<Expr*,SVal> BindingsTy;
+  typedef llvm::ImmutableMap<Stmt*,SVal> BindingsTy;
 
   // Data.
   BindingsTy SubExprBindings;
@@ -55,28 +55,25 @@
   beb_iterator beb_begin() const { return BlkExprBindings.begin(); }
   beb_iterator beb_end() const { return BlkExprBindings.end(); }      
   
-  SVal LookupSubExpr(Expr* E) const {
-    const SVal* X = SubExprBindings.lookup(E);
+  SVal LookupSubExpr(Stmt* E) const {
+    const SVal* X = SubExprBindings.lookup(cast<Expr>(E));
     return X ? *X : UnknownVal();
   }
   
-  SVal LookupBlkExpr(Expr* E) const {
+  SVal LookupBlkExpr(Stmt* E) const {
     const SVal* X = BlkExprBindings.lookup(E);
     return X ? *X : UnknownVal();
   }
   
-  SVal LookupExpr(Expr* E) const {
+  SVal LookupExpr(Stmt* E) const {
     const SVal* X = SubExprBindings.lookup(E);
     if (X) return *X;
     X = BlkExprBindings.lookup(E);
     return X ? *X : UnknownVal();
   }
   
-  SVal GetSVal(Expr* Ex, BasicValueFactory& BasicVals) const;
-  SVal GetSVal(const Expr* Ex, BasicValueFactory& BasicVals) const {
-    return GetSVal(const_cast<Expr*>(Ex), BasicVals);
-  }
-  SVal GetBlkExprSVal(Expr* Ex, BasicValueFactory& BasicVals) const; 
+  SVal GetSVal(Stmt* Ex, BasicValueFactory& BasicVals) const;
+  SVal GetBlkExprSVal(Stmt* Ex, BasicValueFactory& BasicVals) const; 
   
   /// Profile - Profile the contents of an Environment object for use
   ///  in a FoldingSet.
@@ -108,23 +105,23 @@
   ~EnvironmentManager() {}
 
   /// RemoveBlkExpr - Return a new environment object with the same bindings as
-  ///  the provided environment except with any bindings for the provided Expr*
+  ///  the provided environment except with any bindings for the provided Stmt*
   ///  removed.  This method only removes bindings for block-level expressions.
   ///  Using this method on a non-block level expression will return the
   ///  same environment object.
-  Environment RemoveBlkExpr(const Environment& Env, Expr* E) {
+  Environment RemoveBlkExpr(const Environment& Env, Stmt* E) {
     return Environment(Env.SubExprBindings, F.Remove(Env.BlkExprBindings, E));
   }
   
-  Environment RemoveSubExpr(const Environment& Env, Expr* E) {
+  Environment RemoveSubExpr(const Environment& Env, Stmt* E) {
     return Environment(F.Remove(Env.SubExprBindings, E), Env.BlkExprBindings);
   }
   
-  Environment AddBlkExpr(const Environment& Env, Expr* E, SVal V) {
+  Environment AddBlkExpr(const Environment& Env, Stmt* E, SVal V) {
     return Environment(Env.SubExprBindings, F.Add(Env.BlkExprBindings, E, V));
   }
   
-  Environment AddSubExpr(const Environment& Env, Expr* E, SVal V) {
+  Environment AddSubExpr(const Environment& Env, Stmt* E, SVal V) {
     return Environment(F.Add(Env.SubExprBindings, E, V), Env.BlkExprBindings);
   }
   
@@ -139,7 +136,7 @@
     return Environment(F.GetEmptyMap(), F.GetEmptyMap());
   }
   
-  Environment BindExpr(const Environment& Env, Expr* E, SVal V,
+  Environment BindExpr(const Environment& Env, Stmt* E, SVal V,
                        bool isBlkExpr, bool Invalidate);
 
   Environment RemoveDeadBindings(Environment Env, Stmt* Loc,

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h?rev=59152&r1=59151&r2=59152&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Wed Nov 12 13:21:30 2008
@@ -329,7 +329,7 @@
 
   typedef StoreManager::DeadSymbolsTy DeadSymbolsTy;
 
-  const GRState* BindDecl(const GRState* St, const VarDecl* VD, Expr* Ex, 
+  const GRState* BindDecl(const GRState* St, const VarDecl* VD, SVal* IVal,
                           unsigned Count);
   
   /// BindCompoundLiteral - Return the state that has the bindings currently
@@ -391,19 +391,19 @@
 
   // Methods that query & manipulate the Environment.
   
-  SVal GetSVal(const GRState* St, Expr* Ex) {
+  SVal GetSVal(const GRState* St, Stmt* Ex) {
     return St->getEnvironment().GetSVal(Ex, BasicVals);
   }
 
-  SVal GetSVal(const GRState* St, const Expr* Ex) {
-    return St->getEnvironment().GetSVal(Ex, BasicVals);
+  SVal GetSVal(const GRState* St, const Stmt* Ex) {
+    return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), BasicVals);
   }
   
-  SVal GetBlkExprSVal(const GRState* St, Expr* Ex) {
+  SVal GetBlkExprSVal(const GRState* St, Stmt* Ex) {
     return St->getEnvironment().GetBlkExprSVal(Ex, BasicVals);
   }
   
-  const GRState* BindExpr(const GRState* St, Expr* Ex, SVal V,
+  const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V,
                           bool isBlkExpr, bool Invalidate) {
     
     const Environment& OldEnv = St->getEnvironment();
@@ -417,7 +417,7 @@
     return getPersistentState(NewSt);
   }
   
-  const GRState* BindExpr(const GRState* St, Expr* Ex, SVal V,
+  const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V,
                           bool Invalidate = true) {
     
     bool isBlkExpr = false;
@@ -562,20 +562,29 @@
     return Mgr->GetSVal(St, R);
   }
   
-  GRStateRef SetSVal(Expr* Ex, SVal V, bool isBlkExpr, bool Invalidate) {
+  GRStateRef BindExpr(Stmt* Ex, SVal V, bool isBlkExpr, bool Invalidate) {
     return GRStateRef(Mgr->BindExpr(St, Ex, V, isBlkExpr, Invalidate), *Mgr);
   }
   
-  GRStateRef SetSVal(Expr* Ex, SVal V, bool Invalidate = true) {
+  GRStateRef BindExpr(Stmt* Ex, SVal V, bool Invalidate = true) {
     return GRStateRef(Mgr->BindExpr(St, Ex, V, Invalidate), *Mgr);
   }
+    
+  GRStateRef BindDecl(const VarDecl* VD, SVal* InitVal, unsigned Count) {
+    return GRStateRef(Mgr->BindDecl(St, VD, InitVal, Count), *Mgr);
+  }
   
-  GRStateRef SetSVal(Loc LV, SVal V) {
+  GRStateRef BindLoc(Loc LV, SVal V) {
     GRState StImpl = *St;
     Mgr->BindLoc(StImpl, LV, V);    
     return GRStateRef(Mgr->getPersistentState(StImpl), *Mgr);
   }
   
+  GRStateRef BindLoc(SVal LV, SVal V) {
+    if (!isa<Loc>(LV)) return *this;
+    return BindLoc(cast<Loc>(LV), V);
+  }    
+  
   GRStateRef Unbind(Loc LV) {
     return GRStateRef(Mgr->Unbind(St, LV), *Mgr);
   }

Modified: cfe/trunk/lib/Analysis/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Environment.cpp?rev=59152&r1=59151&r2=59152&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/Environment.cpp (original)
+++ cfe/trunk/lib/Analysis/Environment.cpp Wed Nov 12 13:21:30 2008
@@ -1,4 +1,4 @@
-//== Environment.cpp - Map from Expr* to Locations/Values -------*- C++ -*--==//
+//== Environment.cpp - Map from Stmt* to Locations/Values -------*- C++ -*--==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -18,7 +18,7 @@
 
 using namespace clang;
 
-SVal Environment::GetSVal(Expr* E, BasicValueFactory& BasicVals) const {
+SVal Environment::GetSVal(Stmt* E, BasicValueFactory& BasicVals) const {
   
   for (;;) {
     
@@ -58,7 +58,7 @@
         break;
       }
         
-        // Handle all other Expr* using a lookup.
+        // Handle all other Stmt* using a lookup.
         
       default:
         break;
@@ -70,26 +70,30 @@
   return LookupExpr(E);
 }
 
-SVal Environment::GetBlkExprSVal(Expr* E, BasicValueFactory& BasicVals) const {
+SVal Environment::GetBlkExprSVal(Stmt* E, BasicValueFactory& BasicVals) const {
   
-  E = E->IgnoreParens();
-  
-  switch (E->getStmtClass()) {
-    case Stmt::CharacterLiteralClass: {
-      CharacterLiteral* C = cast<CharacterLiteral>(E);
-      return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
-    }
-      
-    case Stmt::IntegerLiteralClass: {
-      return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+  while (1) {
+    switch (E->getStmtClass()) {
+      case Stmt::ParenExprClass:
+        E = cast<ParenExpr>(E)->getSubExpr();
+        continue;
+        
+      case Stmt::CharacterLiteralClass: {
+        CharacterLiteral* C = cast<CharacterLiteral>(E);
+        return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
+      }
+        
+      case Stmt::IntegerLiteralClass: {
+        return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+      }
+        
+      default:
+        return LookupBlkExpr(E);
     }
-      
-    default:
-      return LookupBlkExpr(E);
   }
 }
 
-Environment EnvironmentManager::BindExpr(const Environment& Env, Expr* E,SVal V,
+Environment EnvironmentManager::BindExpr(const Environment& Env, Stmt* E,SVal V,
                                          bool isBlkExpr, bool Invalidate) {  
   assert (E);
   
@@ -115,7 +119,7 @@
   // Iterate over the block-expr bindings.
   for (Environment::beb_iterator I = Env.beb_begin(), E = Env.beb_end(); 
        I != E; ++I) {
-    Expr* BlkExpr = I.getKey();
+    Stmt* BlkExpr = I.getKey();
 
     if (Liveness.isLive(Loc, BlkExpr)) {
       SVal X = I.getData();

Modified: cfe/trunk/lib/Analysis/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRState.cpp?rev=59152&r1=59151&r2=59152&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Wed Nov 12 13:21:30 2008
@@ -73,15 +73,10 @@
 }
 
 const GRState* GRStateManager::BindDecl(const GRState* St, const VarDecl* VD, 
-                                        Expr* Ex, unsigned Count) {
+                                        SVal* InitVal, unsigned Count) {
   Store OldStore = St->getStore();
-  Store NewStore;
+  Store NewStore = StoreMgr->BindDecl(OldStore, VD, InitVal, Count);
 
-  if (Ex)
-    NewStore = StoreMgr->BindDecl(OldStore, VD, Ex, GetSVal(St, Ex), Count);
-  else
-    NewStore = StoreMgr->BindDecl(OldStore, VD, Ex);
-                              
   if (NewStore == OldStore)
     return St;
   





More information about the cfe-commits mailing list