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

Ted Kremenek kremenek at apple.com
Tue Mar 3 16:13:10 PST 2009


Author: kremenek
Date: Tue Mar  3 18:13:10 2009
New Revision: 65982

URL: http://llvm.org/viewvc/llvm-project?rev=65982&view=rev
Log:
Add "GetSValAsScalarOrLoc" methods to GRState/GRStateRef that only perform a
retrieval from the store/environment for locations or scalar types.

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

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=65982&r1=65981&r2=65982&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Tue Mar  3 18:13:10 2009
@@ -407,6 +407,17 @@
   SVal GetSVal(const GRState* St, Stmt* Ex) {
     return St->getEnvironment().GetSVal(Ex, BasicVals);
   }
+  
+  SVal GetSValAsScalarOrLoc(const GRState* state, const Stmt *S) {
+    if (const Expr *Ex = dyn_cast<Expr>(S)) {
+      QualType T = Ex->getType();
+      if (Loc::IsLocType(T) || T->isIntegerType())
+        return GetSVal(state, S);
+    }
+    
+    return UnknownVal();
+  }
+    
 
   SVal GetSVal(const GRState* St, const Stmt* Ex) {
     return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), BasicVals);
@@ -416,6 +427,8 @@
     return St->getEnvironment().GetBlkExprSVal(Ex, BasicVals);
   }
   
+  
+  
   const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V,
                           bool isBlkExpr, bool Invalidate) {
     
@@ -473,6 +486,16 @@
   SVal GetSVal(const GRState* state, const MemRegion* R) {
     return StoreMgr->Retrieve(state, loc::MemRegionVal(R));
   }  
+
+  SVal GetSValAsScalarOrLoc(const GRState* state, const MemRegion *R) {
+    if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
+      QualType T = TR->getRValueType(getContext());
+      if (Loc::IsLocType(T) || T->isIntegerType())
+        return GetSVal(state, R);
+    }
+  
+    return UnknownVal();
+  }
   
   const GRState* BindLoc(const GRState* St, Loc LV, SVal V) {
     return StoreMgr->Bind(St, LV, V);
@@ -637,6 +660,10 @@
     return Mgr->GetBlkExprSVal(St, Ex);
   }
   
+  SVal GetSValAsScalarOrLoc(const Expr *Ex) {
+    return Mgr->GetSValAsScalarOrLoc(St, Ex);
+  }
+
   SVal GetSVal(Loc LV, QualType T = QualType()) {
     return Mgr->GetSVal(St, LV, T);
   }
@@ -645,6 +672,10 @@
     return Mgr->GetSVal(St, R);
   }
   
+  SVal GetSValAsScalarOrLoc(const MemRegion *R) {
+    return Mgr->GetSValAsScalarOrLoc(St, R);
+  }
+
   GRStateRef BindExpr(Stmt* Ex, SVal V, bool isBlkExpr, bool Invalidate) {
     return GRStateRef(Mgr->BindExpr(St, Ex, V, isBlkExpr, Invalidate), *Mgr);
   }

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Tue Mar  3 18:13:10 2009
@@ -257,7 +257,7 @@
 }
   
 bool ScanReachableSymbols::scan(const MemRegion *R) {
-  if (visited.count(R))
+  if (isa<MemSpaceRegion>(R) || visited.count(R))
     return true;
   
   visited.insert(R);
@@ -273,7 +273,7 @@
       return false;
   
   // Now look at the binding to this region (if any).
-  if (!scan(state.GetSVal(R)))
+  if (!scan(state.GetSValAsScalarOrLoc(R)))
     return false;
   
   // Now look at the subregions.





More information about the cfe-commits mailing list