[cfe-commits] r110137 - in /cfe/trunk: include/clang/Checker/PathSensitive/GRState.h include/clang/Checker/PathSensitive/Store.h lib/Checker/CFRefCount.cpp lib/Checker/GRCXXExprEngine.cpp lib/Checker/GRExprEngine.cpp lib/Checker/RegionStore.cpp lib/Checker/Store.cpp

Jordy Rose jediknil at belkadan.com
Tue Aug 3 13:44:35 PDT 2010


Author: jrose
Date: Tue Aug  3 15:44:35 2010
New Revision: 110137

URL: http://llvm.org/viewvc/llvm-project?rev=110137&view=rev
Log:
Makes GRState::makeWithStore private, to encourage clients to make store changes through GRState instead of directly accessing the StoreManager. Also adds cover methods for InvalidateRegion(s) and EnterStackFrame to GRState.

This is in preparation for proposed region change notifications. No functionality change.

Modified:
    cfe/trunk/include/clang/Checker/PathSensitive/GRState.h
    cfe/trunk/include/clang/Checker/PathSensitive/Store.h
    cfe/trunk/lib/Checker/CFRefCount.cpp
    cfe/trunk/lib/Checker/GRCXXExprEngine.cpp
    cfe/trunk/lib/Checker/GRExprEngine.cpp
    cfe/trunk/lib/Checker/RegionStore.cpp
    cfe/trunk/lib/Checker/Store.cpp

Modified: cfe/trunk/include/clang/Checker/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/GRState.h?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/GRState.h Tue Aug  3 15:44:35 2010
@@ -77,6 +77,10 @@
   Store St;
   GenericDataMap   GDM;
 
+  /// makeWithStore - Return a GRState with the same values as the current
+  ///  state with the exception of using the specified Store.
+  const GRState *makeWithStore(Store store) const;
+
 public:
 
   /// This ctor is used when creating the first GRState object.
@@ -134,10 +138,6 @@
     return Env.LookupExpr(E);
   }
 
-  /// makeWithStore - Return a GRState with the same values as the current
-  /// state with the exception of using the specified Store.
-  const GRState *makeWithStore(Store store) const;
-
   BasicValueFactory &getBasicVals() const;
   SymbolManager &getSymbolManager() const;
 
@@ -215,6 +215,28 @@
 
   const GRState *unbindLoc(Loc LV) const;
 
+  /// InvalidateRegion - Returns the state with bindings for the given region
+  ///  cleared from the store. See InvalidateRegions.
+  const GRState *InvalidateRegion(const MemRegion *R,
+                                  const Expr *E, unsigned BlockCount,
+                                  StoreManager::InvalidatedSymbols *IS = NULL)
+                                  const {
+    return InvalidateRegions(&R, &R+1, E, BlockCount, IS, false);
+  }
+
+  /// InvalidateRegions - Returns the state with bindings for the given regions
+  ///  cleared from the store. The regions are provided as a continuous array
+  ///  from Begin to End. Optionally invalidates global regions as well.
+  const GRState *InvalidateRegions(const MemRegion * const *Begin,
+                                   const MemRegion * const *End,
+                                   const Expr *E, unsigned BlockCount,
+                                   StoreManager::InvalidatedSymbols *IS,
+                                   bool invalidateGlobals) const;
+
+  /// EnterStackFrame - Returns the state for entry to the given stack frame,
+  ///  preserving the current state.
+  const GRState *EnterStackFrame(const StackFrameContext *frame) const;
+
   /// Get the lvalue for a variable reference.
   Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
 
@@ -629,6 +651,25 @@
   return makeWithStore(new_store);
 }
 
+inline const GRState *
+GRState::InvalidateRegions(const MemRegion * const *Begin,
+                           const MemRegion * const *End,
+                           const Expr *E, unsigned Count,
+                           StoreManager::InvalidatedSymbols *IS,
+                           bool invalidateGlobals) const {
+  Store new_store
+    = getStateManager().StoreMgr->InvalidateRegions(St, Begin, End,
+                                                    E, Count, IS,
+                                                    invalidateGlobals);
+  return makeWithStore(new_store);
+}
+
+inline const GRState *
+GRState::EnterStackFrame(const StackFrameContext *frame) const {
+  Store new_store = getStateManager().StoreMgr->EnterStackFrame(this, frame);
+  return makeWithStore(new_store);
+}
+
 inline Loc GRState::getLValue(const VarDecl* VD,
                                const LocationContext *LC) const {
   return getStateManager().StoreMgr->getLValueVar(VD, LC);

Modified: cfe/trunk/include/clang/Checker/PathSensitive/Store.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/Store.h?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/Store.h Tue Aug  3 15:44:35 2010
@@ -159,12 +159,7 @@
   virtual Store BindDeclWithNoInit(Store store, const VarRegion *VR) = 0;
 
   typedef llvm::DenseSet<SymbolRef> InvalidatedSymbols;
-  
-  virtual Store InvalidateRegion(Store store,
-                                 const MemRegion *R,
-                                 const Expr *E, unsigned Count,
-                                 InvalidatedSymbols *IS) = 0;
-  
+
   virtual Store InvalidateRegions(Store store,
                                   const MemRegion * const *Begin,
                                   const MemRegion * const *End,
@@ -174,10 +169,8 @@
 
   /// EnterStackFrame - Let the StoreManager to do something when execution
   /// engine is about to execute into a callee.
-  virtual const GRState *EnterStackFrame(const GRState *state,
-                                         const StackFrameContext *frame) {
-    return state;
-  }
+  virtual Store EnterStackFrame(const GRState *state,
+                                const StackFrameContext *frame);
 
   virtual void print(Store store, llvm::raw_ostream& Out,
                      const char* nl, const char *sep) = 0;

Modified: cfe/trunk/lib/Checker/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CFRefCount.cpp?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Checker/CFRefCount.cpp Tue Aug  3 15:44:35 2010
@@ -2712,19 +2712,16 @@
   //  expression (the context) and the expression itself.  This should
   //  disambiguate conjured symbols.
   unsigned Count = Builder.getCurrentBlockCount();
-  StoreManager& StoreMgr = Eng.getStateManager().getStoreManager();
   StoreManager::InvalidatedSymbols IS;
-  Store store = state->getStore();
 
   // NOTE: Even if RegionsToInvalidate is empty, we must still invalidate
   //  global variables.
-  store = StoreMgr.InvalidateRegions(store, RegionsToInvalidate.data(),
-                                     RegionsToInvalidate.data() +
-                                     RegionsToInvalidate.size(),
-                                     Ex, Count, &IS,
-                                     /* invalidateGlobals = */ true);
+  state = state->InvalidateRegions(RegionsToInvalidate.data(),
+                                   RegionsToInvalidate.data() +
+                                   RegionsToInvalidate.size(),
+                                   Ex, Count, &IS,
+                                   /* invalidateGlobals = */ true);
 
-  state = state->makeWithStore(store);
   for (StoreManager::InvalidatedSymbols::iterator I = IS.begin(),
        E = IS.end(); I!=E; ++I) {
     SymbolRef sym = *I;

Modified: cfe/trunk/lib/Checker/GRCXXExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRCXXExprEngine.cpp?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRCXXExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRCXXExprEngine.cpp Tue Aug  3 15:44:35 2010
@@ -197,10 +197,7 @@
     const GRState *state = GetState(*I);
 
     if (ObjTy->isRecordType()) {
-      Store store = state->getStore();
-      StoreManager::InvalidatedSymbols IS;
-      store = getStoreManager().InvalidateRegion(store, EleReg, CNE, Count, &IS);
-      state = state->makeWithStore(store);
+      state = state->InvalidateRegion(EleReg, CNE, Count);
     } else {
       if (CNE->hasInitializer()) {
         SVal V = state->getSVal(*CNE->constructor_arg_begin());

Modified: cfe/trunk/lib/Checker/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/GRExprEngine.cpp?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Checker/GRExprEngine.cpp Tue Aug  3 15:44:35 2010
@@ -1454,8 +1454,7 @@
                          B.getBlock(),
                          B.getIndex());
 
-  const GRState *state = B.getState();
-  state = getStoreManager().EnterStackFrame(state, LocCtx);
+  const GRState *state = B.getState()->EnterStackFrame(LocCtx);
 
   B.GenerateNode(state, LocCtx);
 }

Modified: cfe/trunk/lib/Checker/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/RegionStore.cpp?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/RegionStore.cpp (original)
+++ cfe/trunk/lib/Checker/RegionStore.cpp Tue Aug  3 15:44:35 2010
@@ -357,8 +357,7 @@
                                     SymbolReaper& SymReaper,
                           llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
 
-  const GRState *EnterStackFrame(const GRState *state,
-                                 const StackFrameContext *frame);
+  Store EnterStackFrame(const GRState *state, const StackFrameContext *frame);
 
   //===------------------------------------------------------------------===//
   // Region "extents".
@@ -1841,8 +1840,8 @@
 }
 
 
-GRState const *RegionStoreManager::EnterStackFrame(GRState const *state,
-                                               StackFrameContext const *frame) {
+Store RegionStoreManager::EnterStackFrame(const GRState *state,
+                                          const StackFrameContext *frame) {
   FunctionDecl const *FD = cast<FunctionDecl>(frame->getDecl());
   FunctionDecl::param_const_iterator PI = FD->param_begin();
   Store store = state->getStore();
@@ -1866,9 +1865,9 @@
       store = Bind(store, ValMgr.makeLoc(MRMgr.getVarRegion(*PI,frame)),ArgVal);
     }
   } else
-    assert(0 && "Unhandled call expression.");
+    llvm_unreachable("Unhandled call expression.");
 
-  return state->makeWithStore(store);
+  return store;
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Checker/Store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/Store.cpp?rev=110137&r1=110136&r2=110137&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/Store.cpp (original)
+++ cfe/trunk/lib/Checker/Store.cpp Tue Aug  3 15:44:35 2010
@@ -21,6 +21,11 @@
   : ValMgr(stateMgr.getValueManager()), StateMgr(stateMgr),
     MRMgr(ValMgr.getRegionManager()), Ctx(stateMgr.getContext()) {}
 
+Store StoreManager::EnterStackFrame(const GRState *state,
+                                    const StackFrameContext *frame) {
+  return state->getStore();
+}
+
 const MemRegion *StoreManager::MakeElementRegion(const MemRegion *Base,
                                               QualType EleTy, uint64_t index) {
   SVal idx = ValMgr.makeArrayIndex(index);





More information about the cfe-commits mailing list