]> granicus.if.org Git - clang/commitdiff
Remove more uses of GRStateRef.
authorTed Kremenek <kremenek@apple.com>
Wed, 17 Jun 2009 22:28:13 +0000 (22:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 17 Jun 2009 22:28:13 +0000 (22:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73648 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/GRState.h
lib/Analysis/BasicConstraintManager.cpp
lib/Analysis/CheckNSError.cpp
lib/Analysis/RangeConstraintManager.cpp

index 700e9f6ec91b82ae5706233d0766277da31ee3c9..ae5423111fcdc568173253ada22f42d3989e4868 100644 (file)
@@ -155,7 +155,24 @@ public:
   typedef Environment::beb_iterator beb_iterator;
   beb_iterator beb_begin() const { return Env.beb_begin(); }
   beb_iterator beb_end() const { return Env.beb_end(); }
+  
+  BasicValueFactory &getBasicVals() const;
+  SymbolManager &getSymbolManager() const;
+
+  SVal getLValue(const VarDecl* VD) const;
 
+  SVal getSVal(Expr* Ex) const;
+  
+  SVal getBlkExprSVal(Expr* Ex) const;
+  
+  SVal getSValAsScalarOrLoc(const Expr *Ex) const;
+  
+  SVal getSVal(Loc LV, QualType T = QualType()) const;
+  
+  SVal getSVal(const MemRegion* R) const;
+  
+  SVal getSValAsScalarOrLoc(const MemRegion *R) const;
+  
   // Trait based GDM dispatch.  
   void* const* FindGDM(void* K) const;
   
@@ -697,9 +714,45 @@ public:
   
 
 //===----------------------------------------------------------------------===//
-// Out-of-line template method definitions for GRState.
+// Out-of-line method definitions for GRState.
 //===----------------------------------------------------------------------===//
 
+inline SVal GRState::getLValue(const VarDecl* VD) const {
+  return Mgr->GetLValue(this, VD);
+}  
+  
+inline SVal GRState::getSVal(Expr* Ex) const {
+  return Mgr->GetSVal(this, Ex);
+}
+
+inline SVal GRState::getBlkExprSVal(Expr* Ex) const {  
+  return Mgr->GetBlkExprSVal(this, Ex);
+}
+
+inline SVal GRState::getSValAsScalarOrLoc(const Expr *Ex) const {
+  return Mgr->GetSValAsScalarOrLoc(this, Ex);
+}
+
+inline SVal GRState::getSVal(Loc LV, QualType T) const {
+  return Mgr->GetSVal(this, LV, T);
+}
+
+inline SVal GRState::getSVal(const MemRegion* R) const {
+  return Mgr->GetSVal(this, R);
+}
+
+inline SVal GRState::getSValAsScalarOrLoc(const MemRegion *R) const {
+  return Mgr->GetSValAsScalarOrLoc(this, R);
+}
+  
+inline BasicValueFactory& GRState::getBasicVals() const {
+  return Mgr->getBasicVals();
+}
+
+inline SymbolManager& GRState::getSymbolManager() const {
+  return Mgr->getSymbolManager();
+}
+
 template<typename T>
 const GRState *GRState::add(typename GRStateTrait<T>::key_type K) const {
   return Mgr->add<T>(this, K, get_context<T>());
index b2722141d9552568d8849a2ff2bf6db6fc3125df..1f907baa24997b8792cfc44bdd3e5cf899fdd51e 100644 (file)
@@ -226,28 +226,24 @@ BasicConstraintManager::AssumeSymLE(const GRState* St, SymbolRef sym,
   return St;
 }
 
-const GRState* BasicConstraintManager::AddEQ(const GRState* St, SymbolRef sym,
+const GRState* BasicConstraintManager::AddEQ(const GRState* state, SymbolRef sym,
                                              const llvm::APSInt& V) {
   // Create a new state with the old binding replaced.
-  GRStateRef state(St, StateMgr);
-  return state.set<ConstEq>(sym, &V);
+  return state->set<ConstEq>(sym, &V);
 }
 
-const GRState* BasicConstraintManager::AddNE(const GRState* St, SymbolRef sym,
+const GRState* BasicConstraintManager::AddNE(const GRState* state, SymbolRef sym,
                                              const llvm::APSInt& V) {
 
-  GRStateRef state(St, StateMgr);
-
   // First, retrieve the NE-set associated with the given symbol.
-  ConstNotEqTy::data_type* T = state.get<ConstNotEq>(sym);
+  ConstNotEqTy::data_type* T = state->get<ConstNotEq>(sym);
   GRState::IntSetTy S = T ? *T : ISetFactory.GetEmptySet();
-
   
   // Now add V to the NE set.
   S = ISetFactory.Add(S, &V);
   
   // Create a new state with the old binding replaced.
-  return state.set<ConstNotEq>(sym, S);
+  return state->set<ConstNotEq>(sym, S);
 }
 
 const llvm::APSInt* BasicConstraintManager::getSymVal(const GRState* St,
@@ -277,28 +273,27 @@ bool BasicConstraintManager::isEqual(const GRState* St, SymbolRef sym,
 /// Scan all symbols referenced by the constraints. If the symbol is not alive
 /// as marked in LSymbols, mark it as dead in DSymbols.
 const GRState*
-BasicConstraintManager::RemoveDeadBindings(const GRState* St,
+BasicConstraintManager::RemoveDeadBindings(const GRState* state,
                                            SymbolReaper& SymReaper) {
 
-  GRStateRef state(St, StateMgr);
-  ConstEqTy CE = state.get<ConstEq>();
-  ConstEqTy::Factory& CEFactory = state.get_context<ConstEq>();
+  ConstEqTy CE = state->get<ConstEq>();
+  ConstEqTy::Factory& CEFactory = state->get_context<ConstEq>();
 
   for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) {
     SymbolRef sym = I.getKey();
     if (SymReaper.maybeDead(sym)) CE = CEFactory.Remove(CE, sym);
   }
-  state = state.set<ConstEq>(CE);
+  state = state->set<ConstEq>(CE);
 
-  ConstNotEqTy CNE = state.get<ConstNotEq>();
-  ConstNotEqTy::Factory& CNEFactory = state.get_context<ConstNotEq>();
+  ConstNotEqTy CNE = state->get<ConstNotEq>();
+  ConstNotEqTy::Factory& CNEFactory = state->get_context<ConstNotEq>();
 
   for (ConstNotEqTy::iterator I = CNE.begin(), E = CNE.end(); I != E; ++I) {
     SymbolRef sym = I.getKey();    
     if (SymReaper.maybeDead(sym)) CNE = CNEFactory.Remove(CNE, sym);
   }
   
-  return state.set<ConstNotEq>(CNE);
+  return state->set<ConstNotEq>(CNE);
 }
 
 void BasicConstraintManager::print(const GRState* St, std::ostream& Out, 
index ff9da0f659c3687f70675741bed3b2ad1d4410f5..c91442b5e82915a09599fe224eadcc1fbe4ab8ff 100644 (file)
@@ -41,7 +41,7 @@ class VISIBILITY_HIDDEN NSErrorCheck : public BugType {
   bool CheckNSErrorArgument(QualType ArgTy);
   bool CheckCFErrorArgument(QualType ArgTy);
   
-  void CheckParamDeref(VarDecl* V, GRStateRef state, BugReporter& BR);
+  void CheckParamDeref(VarDecl* V, const GRState *state, BugReporter& BR);
   
   void EmitRetTyWarning(BugReporter& BR, Decl& CodeDecl);
   
@@ -94,8 +94,7 @@ void NSErrorCheck::FlushReports(BugReporter& BR) {
     // Scan the parameters for an implicit null dereference.
     for (llvm::SmallVectorImpl<VarDecl*>::iterator I=ErrorParams.begin(),
           E=ErrorParams.end(); I!=E; ++I)    
-        CheckParamDeref(*I, GRStateRef((*RI)->getState(),Eng.getStateManager()),
-                        BR);
+        CheckParamDeref(*I, (*RI)->getState(), BR);
 
   }
 }
@@ -186,13 +185,13 @@ bool NSErrorCheck::CheckCFErrorArgument(QualType ArgTy) {
   return TT->getDecl()->getIdentifier() == II;
 }
 
-void NSErrorCheck::CheckParamDeref(VarDecl* Param, GRStateRef rootState,
+void NSErrorCheck::CheckParamDeref(VarDecl* Param, const GRState *rootState,
                                    BugReporter& BR) {
   
-  SVal ParamL = rootState.GetLValue(Param);
+  SVal ParamL = rootState->getLValue(Param);
   const MemRegion* ParamR = cast<loc::MemRegionVal>(ParamL).getRegionAs<VarRegion>();
   assert (ParamR && "Parameters always have VarRegions.");
-  SVal ParamSVal = rootState.GetSVal(ParamR);
+  SVal ParamSVal = rootState->getSVal(ParamR);
   
   // FIXME: For now assume that ParamSVal is symbolic.  We need to generalize
   // this later.
@@ -204,8 +203,8 @@ void NSErrorCheck::CheckParamDeref(VarDecl* Param, GRStateRef rootState,
   for (GRExprEngine::null_deref_iterator I=Eng.implicit_null_derefs_begin(),
        E=Eng.implicit_null_derefs_end(); I!=E; ++I) {
     
-    GRStateRef state = GRStateRef((*I)->getState(), Eng.getStateManager());
-    const SVal* X = state.get<GRState::NullDerefTag>();    
+    const GRState *state = (*I)->getState();
+    const SVal* X = state->get<GRState::NullDerefTag>();    
 
     if (!X || X->getAsSymbol() != ParamSym)
       continue;
index f6ac2b9748c41322c3ef4d86896b0f3e28313121..89f3a716d2472557a7c0c9cc2f73dda6fb6d79dc 100644 (file)
@@ -233,7 +233,7 @@ struct GRStateTrait<ConstraintRange>
   
 namespace {
 class VISIBILITY_HIDDEN RangeConstraintManager : public SimpleConstraintManager{
-  RangeSet GetRange(GRStateRef state, SymbolRef sym);      
+  RangeSet GetRange(const GRState *state, SymbolRef sym);      
 public:
   RangeConstraintManager(GRStateManager& statemgr) 
       : SimpleConstraintManager(statemgr) {}
@@ -289,12 +289,11 @@ const llvm::APSInt* RangeConstraintManager::getSymVal(const GRState* St,
 /// Scan all symbols referenced by the constraints. If the symbol is not alive
 /// as marked in LSymbols, mark it as dead in DSymbols.
 const GRState*
-RangeConstraintManager::RemoveDeadBindings(const GRState* St,
+RangeConstraintManager::RemoveDeadBindings(const GRState* state,
                                            SymbolReaper& SymReaper) {
-  GRStateRef state(St, StateMgr);
 
-  ConstraintRangeTy CR = state.get<ConstraintRange>();
-  ConstraintRangeTy::Factory& CRFactory = state.get_context<ConstraintRange>();
+  ConstraintRangeTy CR = state->get<ConstraintRange>();
+  ConstraintRangeTy::Factory& CRFactory = state->get_context<ConstraintRange>();
 
   for (ConstraintRangeTy::iterator I = CR.begin(), E = CR.end(); I != E; ++I) {
     SymbolRef sym = I.getKey();    
@@ -302,7 +301,7 @@ RangeConstraintManager::RemoveDeadBindings(const GRState* St,
       CR = CRFactory.Remove(CR, sym);
   }
   
-  return state.set<ConstraintRange>(CR);
+  return state->set<ConstraintRange>(CR);
 }
 
 //===------------------------------------------------------------------------===
@@ -310,14 +309,14 @@ RangeConstraintManager::RemoveDeadBindings(const GRState* St,
 //===------------------------------------------------------------------------===/
 
 RangeSet
-RangeConstraintManager::GetRange(GRStateRef state, SymbolRef sym) {
-  if (ConstraintRangeTy::data_type* V = state.get<ConstraintRange>(sym))
+RangeConstraintManager::GetRange(const GRState *state, SymbolRef sym) {
+  if (ConstraintRangeTy::data_type* V = state->get<ConstraintRange>(sym))
     return *V;
   
   // Lazily generate a new RangeSet representing all possible values for the
   // given symbol type.
-  QualType T = state.getSymbolManager().getType(sym);
-  BasicValueFactory& BV = state.getBasicVals();  
+  QualType T = state->getSymbolManager().getType(sym);
+  BasicValueFactory& BV = state->getBasicVals();  
   return RangeSet(F, BV.getMinValue(T), BV.getMaxValue(T));
 }
 
@@ -327,12 +326,11 @@ RangeConstraintManager::GetRange(GRStateRef state, SymbolRef sym) {
 
 #define AssumeX(OP)\
 const GRState*\
-RangeConstraintManager::AssumeSym ## OP(const GRState* St, SymbolRef sym,\
+RangeConstraintManager::AssumeSym ## OP(const GRState* state, SymbolRef sym,\
   const llvm::APSInt& V, bool& isFeasible){\
-  GRStateRef state(St, StateMgr);\
-  const RangeSet& R = GetRange(state, sym).Add##OP(state.getBasicVals(), F, V);\
+  const RangeSet& R = GetRange(state, sym).Add##OP(state->getBasicVals(), F, V);\
   isFeasible = !R.isEmpty();\
-  return isFeasible ? state.set<ConstraintRange>(sym, R).getState() : 0;\
+  return isFeasible ? state->set<ConstraintRange>(sym, R) : 0;\
 }
 
 AssumeX(EQ)