]> granicus.if.org Git - clang/commitdiff
- Move ownership of MemRegionManager into ValueManager.
authorTed Kremenek <kremenek@apple.com>
Thu, 9 Apr 2009 22:22:44 +0000 (22:22 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 9 Apr 2009 22:22:44 +0000 (22:22 +0000)
- Pull SVal::GetConjuredSymbol() and friends into ValueManager. This greatly
simplifies the calling interface to clients.

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

include/clang/Analysis/PathSensitive/GRState.h
include/clang/Analysis/PathSensitive/SVals.h
include/clang/Analysis/PathSensitive/Store.h
include/clang/Analysis/PathSensitive/ValueManager.h
lib/Analysis/BasicStore.cpp
lib/Analysis/CFRefCount.cpp
lib/Analysis/GRExprEngine.cpp
lib/Analysis/GRSimpleVals.cpp
lib/Analysis/RegionStore.cpp
lib/Analysis/SVals.cpp

index aa794175b10bc4cd66ad8c72cd27da2ed1ceb65b..4c75c86c9f1c2fc6d6f994c3ec5eaea334992201 100644 (file)
@@ -310,9 +310,6 @@ public:
     Liveness(L) {
       StoreMgr.reset((*CreateStoreManager)(*this));
       ConstraintMgr.reset((*CreateConstraintManager)(*this));
-      
-      // FIXME: Have ValueMgr own the MemRegionManager, not StoreManager.
-      ValueMgr.setRegionManager(StoreMgr->getRegionManager());
   }
   
   ~GRStateManager();
index df407801815c49bfd118a5d1630c317f83285764..73c5509d2ef6257a44e95e057c3535431e892ec4 100644 (file)
@@ -72,15 +72,6 @@ public:
     return !(*this == R);
   }
 
-  /// GetRValueSymbolVal - make a unique symbol for value of R.
-  static SVal GetRValueSymbolVal(SymbolManager& SymMgr, MemRegionManager& MRMgr,
-                                 const MemRegion* R);
-
-  static SVal GetConjuredSymbolVal(SymbolManager& SymMgr, MemRegionManager&,
-                                   const Expr *E, unsigned Count);  
-  static SVal GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager&,
-                                   const Expr* E, QualType T, unsigned Count);
-
   inline bool isUnknown() const {
     return getRawKind() == UnknownKind;
   }
index ea7c496ff92a99970d9970c0770d12efb5d432a3..9d41de7bd5b6fa9ab2d7d86a8fdb5b2095fc5af1 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "clang/Analysis/PathSensitive/SVals.h"
 #include "clang/Analysis/PathSensitive/MemRegion.h"
+#include "clang/Analysis/PathSensitive/ValueManager.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/DenseSet.h"
@@ -35,10 +36,13 @@ class SubRegionMap;
   
 class StoreManager {
 protected:
+  ValueManager &ValMgr;
+
   /// MRMgr - Manages region objects associated with this StoreManager.
-  MemRegionManager MRMgr;
+  MemRegionManager &MRMgr;
 
-  StoreManager(llvm::BumpPtrAllocator& Alloc) : MRMgr(Alloc) {}
+  StoreManager(ValueManager &valMgr)
+    : ValMgr(valMgr), MRMgr(ValMgr.getRegionManager()) {}
 
 public:  
   virtual ~StoreManager() {}
index 28aa791c0234d9cc0b3ffde1038fee8797d24945..f83b02c227129413f1457b753f3715ee4b967eed 100644 (file)
 #include "clang/Analysis/PathSensitive/SymbolManager.h"
 
 namespace llvm { class BumpPtrAllocator; }
-namespace clang { class GRStateManager; }
 
 namespace clang {  
 class ValueManager {
-  friend class GRStateManager;
 
   ASTContext &Context;  
   BasicValueFactory BasicVals;
@@ -34,16 +32,14 @@ class ValueManager {
   /// SymMgr - Object that manages the symbol information.
   SymbolManager SymMgr;
 
-  // FIXME: Eventually ValueManager will own this object.
-  MemRegionManager *MemMgr;
 
-  void setRegionManager(MemRegionManager& mm) { MemMgr = &mm; }
+  MemRegionManager MemMgr;
   
 public:
   ValueManager(llvm::BumpPtrAllocator &alloc, ASTContext &context)
                : Context(context), BasicVals(Context, alloc),
                  SymMgr(Context, BasicVals, alloc),
-                 MemMgr(0) {}
+                 MemMgr(alloc) {}
 
   // Accessors to submanagers.
   
@@ -56,8 +52,8 @@ public:
   SymbolManager &getSymbolManager() { return SymMgr; }
   const SymbolManager &getSymbolManager() const { return SymMgr; }
 
-  MemRegionManager &getRegionManager() { return *MemMgr; }
-  const MemRegionManager &getRegionManager() const { return *MemMgr; }
+  MemRegionManager &getRegionManager() { return MemMgr; }
+  const MemRegionManager &getRegionManager() const { return MemMgr; }
   
   // Forwarding methods to SymbolManager.
   
@@ -75,11 +71,17 @@ public:
   // Aggregation methods that use multiple submanagers.
   
   Loc makeRegionVal(SymbolRef Sym) {
-    return Loc::MakeVal(MemMgr->getSymbolicRegion(Sym));
+    return Loc::MakeVal(MemMgr.getSymbolicRegion(Sym));
   }
   
   /// makeZeroVal - Construct an SVal representing '0' for the specified type.
   SVal makeZeroVal(QualType T);
+  
+  /// GetRValueSymbolVal - make a unique symbol for value of R.
+  SVal getRValueSymbolVal(const MemRegion* R);
+  
+  SVal getConjuredSymbolVal(const Expr *E, unsigned Count);  
+  SVal getConjuredSymbolVal(const Expr* E, QualType T, unsigned Count);
 };
 } // end clang namespace
 #endif
index c1efb983c049a50813dcd5cba0e6db44eab5a76b..5c234549a4c678391c4f83e1d6aa0e8bba2ec1b2 100644 (file)
@@ -40,7 +40,7 @@ class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager {
   
 public:
   BasicStoreManager(GRStateManager& mgr)
-    : StoreManager(mgr.getAllocator()),
+    : StoreManager(mgr.getValueManager()),
       VBFactory(mgr.getAllocator()), 
       StateMgr(mgr), 
       SelfRegion(0) {}
@@ -478,11 +478,8 @@ Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl, Store St) {
       if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Base)) {
         if (DR->getDecl() == SelfDecl) {
           const MemRegion *IVR = MRMgr.getObjCIvarRegion(IV->getDecl(),
-                                                         SelfRegion);
-          
-          SVal X = SVal::GetRValueSymbolVal(StateMgr.getSymbolManager(),
-                                            MRMgr, IVR);
-          
+                                                         SelfRegion);          
+          SVal X = ValMgr.getRValueSymbolVal(IVR);          
           St = BindInternal(St, Loc::MakeVal(IVR), X);
         }
       }
@@ -538,7 +535,7 @@ Store BasicStoreManager::getInitialStore() {
       const MemRegion *R = StateMgr.getRegion(VD);
       SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
                 isa<ImplicitParamDecl>(VD))
-            ? SVal::GetRValueSymbolVal(StateMgr.getSymbolManager(), MRMgr,R)
+            ? ValMgr.getRValueSymbolVal(R)
             : UndefinedVal();
 
       St = BindInternal(St, Loc::MakeVal(R), X);
index 0a68ee49de2239ab8b3cdeefd2aba16cc457633e..cfeabd0cb1b06c06b07e7f578f0b0aa7fa43ead3 100644 (file)
@@ -1760,8 +1760,8 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
             QualType T = R->getRValueType(Ctx);
           
             if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())){
-              SVal V = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
-                        Eng.getStoreManager().getRegionManager(), *I, T, Count);
+              ValueManager &ValMgr = Eng.getValueManager();
+              SVal V = ValMgr.getConjuredSymbolVal(*I, T, Count);
               state = state.BindLoc(Loc::MakeVal(R), V);
             }
             else if (const RecordType *RT = T->getAsStructureType()) {
@@ -1787,13 +1787,10 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
                 QualType FT = FD->getType();
                 
                 if (Loc::IsLocType(FT) || 
-                    (FT->isIntegerType() && FT->isScalarType())) {
-                  
+                    (FT->isIntegerType() && FT->isScalarType())) {                  
                   const FieldRegion* FR = MRMgr.getFieldRegion(FD, R);
-
-                  SVal V = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
-                       Eng.getStoreManager().getRegionManager(), *I, FT, Count);
-
+                  ValueManager &ValMgr = Eng.getValueManager();
+                  SVal V = ValMgr.getConjuredSymbolVal(*I, FT, Count);
                   state = state.BindLoc(Loc::MakeVal(FR), V);
                 }                
               }
@@ -1857,8 +1854,8 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
       
       if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) {
         unsigned Count = Builder.getCurrentBlockCount();
-        SVal X = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
-                       Eng.getStoreManager().getRegionManager(), Ex, T, Count);
+        ValueManager &ValMgr = Eng.getValueManager();
+        SVal X = ValMgr.getConjuredSymbolVal(Ex, T, Count);
         state = state.BindExpr(Ex, X, false);
       }      
       
index 2a43b9a89eaaa96ce7c57af97323559c470cb4aa..c7ff0aec27ff7ca34dde9eb6967a67af93f54879 100644 (file)
@@ -2139,8 +2139,7 @@ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst) {
       // UnknownVal.
       if (InitVal.isUnknown() || 
           !getConstraintManager().canReasonAbout(InitVal)) {
-        InitVal = SVal::GetConjuredSymbolVal(SymMgr, 
-                          getStoreManager().getRegionManager(), InitEx, Count);
+        InitVal = ValMgr.getConjuredSymbolVal(InitEx, Count);
       }        
       
       state = StateMgr.BindDecl(state, VD, InitVal);
@@ -2531,9 +2530,8 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred,
       
       // Conjure a new symbol if necessary to recover precision.
       if (Result.isUnknown() || !getConstraintManager().canReasonAbout(Result))
-        Result = SVal::GetConjuredSymbolVal(SymMgr, 
-                                       getStoreManager().getRegionManager(),Ex,
-                                            Builder->getCurrentBlockCount());
+        Result = ValMgr.getConjuredSymbolVal(Ex,
+                                             Builder->getCurrentBlockCount());
       
       state = BindExpr(state, U, U->isPostfix() ? V2 : Result);
 
@@ -2758,10 +2756,8 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
                !getConstraintManager().canReasonAbout(RightV))              
               && (Loc::IsLocType(T) || 
                   (T->isScalarType() && T->isIntegerType()))) {
-            unsigned Count = Builder->getCurrentBlockCount();
-            
-            RightV = SVal::GetConjuredSymbolVal(SymMgr, 
-                      getStoreManager().getRegionManager(), B->getRHS(), Count);
+            unsigned Count = Builder->getCurrentBlockCount();            
+            RightV = ValMgr.getConjuredSymbolVal(B->getRHS(), Count);
           }
           
           // Simulate the effects of a "store":  bind the value of the RHS
@@ -2932,8 +2928,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
           // The symbolic value is actually for the type of the left-hand side
           // expression, not the computation type, as this is the value the
           // LValue on the LHS will bind to.
-          LHSVal = SVal::GetConjuredSymbolVal(SymMgr, 
-                getStoreManager().getRegionManager(), B->getRHS(), LTy, Count);
+          LHSVal = ValMgr.getConjuredSymbolVal(B->getRHS(), LTy, Count);
           
           // However, we need to convert the symbol to the computation type.
           Result = (LTy == CTy) ? LHSVal : EvalCast(LHSVal,CTy);
index 44e76555f942c9a026193999af5c1c6f3bd694f9..8d596955be4406f1d9c6b1776cb2b27e336101d1 100644 (file)
@@ -449,10 +449,7 @@ void GRSimpleVals::EvalCall(ExplodedNodeSet<GRState>& Dst,
   QualType T = CE->getType();  
   if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) {    
     unsigned Count = Builder.getCurrentBlockCount();
-        
-    SVal X = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
-                          Eng.getStoreManager().getRegionManager(), CE, Count);
-    
+    SVal X = Eng.getValueManager().getConjuredSymbolVal(CE, Count);
     St = StateMgr.BindExpr(St, CE, X, Eng.getCFG().isBlkExpr(CE), false);
   }  
     
index 5e60363573ce62721c07b2fa2034939fb6c96db8..4088158627f23e663a4d0d15acebae07a3e19c77 100644 (file)
@@ -148,7 +148,7 @@ class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
 
 public:
   RegionStoreManager(GRStateManager& mgr) 
-    : StoreManager(mgr.getAllocator()),
+    : StoreManager(mgr.getValueManager()),
       RBFactory(mgr.getAllocator()),
       RVFactory(mgr.getAllocator()),
       StateMgr(mgr), SelfRegion(0), SelfDecl(0) {
@@ -159,8 +159,6 @@ public:
 
   virtual ~RegionStoreManager() {}
 
-  MemRegionManager& getRegionManager() { return MRMgr; }
-  
   SubRegionMap* getSubRegionMap(const GRState *state);
   
   const GRState* BindCompoundLiteral(const GRState* St, 
@@ -756,7 +754,7 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
     if (SR == SelfRegion) {
       // FIXME: Do we need to handle the case where the super region
       // has a view?  We want to canonicalize the bindings.
-      return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, R);
+      return ValMgr.getRValueSymbolVal(R);
     }
     
     // Otherwise, we need a new symbol.  For now return Unknown.
@@ -778,7 +776,7 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
         VD->hasGlobalStorage()) {
       QualType VTy = VD->getType();
       if (Loc::IsLocType(VTy) || VTy->isIntegerType())
-        return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, VR);
+        return ValMgr.getRValueSymbolVal(VR);
       else
         return UnknownVal();
     }
@@ -794,7 +792,7 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
 
   // All other integer values are symbolic.
   if (Loc::IsLocType(RTy) || RTy->isIntegerType())
-    return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, R);
+    return ValMgr.getRValueSymbolVal(R);
   else
     return UnknownVal();
 }
@@ -833,7 +831,7 @@ SVal RegionStoreManager::RetrieveStruct(const GRState* St,const TypedRegion* R){
       if (MRMgr.onStack(FR) || MRMgr.onHeap(FR))
         FieldValue = UndefinedVal();
       else
-        FieldValue = SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, FR);
+        FieldValue = ValMgr.getRValueSymbolVal(FR);
     }
 
     StructVal = getBasicVals().consVals(FieldValue, StructVal);
index 8fdc37fe73750e5d0377b2ac30e77df43f37677f..acc4111b70ca146a6f8c9c5901512a04926a2908 100644 (file)
@@ -280,15 +280,14 @@ NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
   return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
 }
 
-SVal SVal::GetRValueSymbolVal(SymbolManager& SymMgr, MemRegionManager& MRMgr,
-                              const MemRegion* R) {
+SVal ValueManager::getRValueSymbolVal(const MemRegion* R) {
   SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
                                 
   if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
     QualType T = TR->getRValueType(SymMgr.getContext());
     
     if (Loc::IsLocType(T))
-      return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+      return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
   
     // Only handle integers for now.
     if (T->isIntegerType() && T->isScalarType())
@@ -298,13 +297,12 @@ SVal SVal::GetRValueSymbolVal(SymbolManager& SymMgr, MemRegionManager& MRMgr,
   return UnknownVal();
 }
 
-SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager& MRMgr,
-                                const Expr* E, unsigned Count) {
+SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
   QualType T = E->getType();
   SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
 
   if (Loc::IsLocType(T))
-    return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+    return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
 
   if (T->isIntegerType() && T->isScalarType())
     return NonLoc::MakeVal(sym);
@@ -312,12 +310,13 @@ SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager& MRMgr,
   return UnknownVal();
 }
 
-SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager& MRMgr,
-                                const Expr* E, QualType T, unsigned Count) {
+SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
+                                        unsigned Count) {
+
   SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
 
   if (Loc::IsLocType(T))
-    return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+    return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
 
   if (T->isIntegerType() && T->isScalarType())
     return NonLoc::MakeVal(sym);