[cfe-commits] r65914 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Store.h lib/Analysis/BasicStore.cpp lib/Analysis/RegionStore.cpp
Ted Kremenek
kremenek at apple.com
Mon Mar 2 17:35:36 PST 2009
Author: kremenek
Date: Mon Mar 2 19:35:36 2009
New Revision: 65914
URL: http://llvm.org/viewvc/llvm-project?rev=65914&view=rev
Log:
Add StoreManager::getSubRegionMap(). This method returns an opaque mapping for clients of StoreManagers from MemRegions to their subregions.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/RegionStore.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Store.h?rev=65914&r1=65913&r2=65914&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Mon Mar 2 19:35:36 2009
@@ -31,7 +31,8 @@
class Stmt;
class Expr;
class ObjCIvarDecl;
-
+class SubRegionMap;
+
class StoreManager {
protected:
/// MRMgr - Manages region objects associated with this StoreManager.
@@ -71,8 +72,17 @@
const CompoundLiteralExpr* CL,
SVal V) = 0;
+ /// getInitialStore - Returns the initial "empty" store representing the
+ /// value bindings upon entry to an analyzed function.
virtual Store getInitialStore() = 0;
+
+ /// getRegionManager - Returns the internal RegionManager object that is
+ /// used to query and manipulate MemRegion objects.
MemRegionManager& getRegionManager() { return MRMgr; }
+
+ /// getSubRegionMap - Returns an opaque map object that clients can query
+ /// to get the subregions of a given MemRegion object.
+ virtual std::auto_ptr<SubRegionMap> getSubRegionMap(const GRState *state) = 0;
virtual SVal getLValueVar(const GRState* St, const VarDecl* VD) = 0;
@@ -151,6 +161,21 @@
/// iterBindings - Iterate over the bindings in the Store.
virtual void iterBindings(Store store, BindingsHandler& f) = 0;
};
+
+/// SubRegionMap - An abstract interface that represents a queryable map
+/// between MemRegion objects and their subregions.
+class SubRegionMap {
+public:
+ virtual ~SubRegionMap() {}
+
+ class Visitor {
+ public:
+ virtual ~Visitor() {}
+ virtual bool Visit(const MemRegion* Parent, const MemRegion* SubRegion);
+ };
+
+ virtual void iterSubRegions(const MemRegion* R, Visitor& V) const = 0;
+};
StoreManager* CreateBasicStoreManager(GRStateManager& StMgr);
StoreManager* CreateRegionStoreManager(GRStateManager& StMgr);
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=65914&r1=65913&r2=65914&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Mon Mar 2 19:35:36 2009
@@ -23,6 +23,15 @@
namespace {
+class VISIBILITY_HIDDEN BasicStoreSubRegionMap : public SubRegionMap {
+public:
+ BasicStoreSubRegionMap() {}
+
+ void iterSubRegions(const MemRegion* R, Visitor& V) const {
+ // Do nothing. No subregions.
+ }
+};
+
class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager {
VarBindingsTy::Factory VBFactory;
GRStateManager& StateMgr;
@@ -37,6 +46,10 @@
~BasicStoreManager() {}
+ std::auto_ptr<SubRegionMap> getSubRegionMap(const GRState *state) {
+ return std::auto_ptr<SubRegionMap>(new BasicStoreSubRegionMap());
+ }
+
SVal Retrieve(const GRState *state, Loc loc, QualType T = QualType());
const GRState* Bind(const GRState* St, Loc L, SVal V) {
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=65914&r1=65913&r2=65914&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Mon Mar 2 19:35:36 2009
@@ -105,6 +105,37 @@
namespace {
+class VISIBILITY_HIDDEN RegionStoreSubRegionMap : public SubRegionMap {
+ typedef llvm::DenseMap<const MemRegion*,
+ llvm::ImmutableSet<const MemRegion*> > Map;
+
+ llvm::ImmutableSet<const MemRegion*>::Factory F;
+ Map M;
+
+public:
+ void add(const MemRegion* Parent, const MemRegion* SubRegion) {
+ Map::iterator I = M.find(Parent);
+ M.insert(std::make_pair(Parent,
+ F.Add(I == M.end() ? F.GetEmptySet() : I->second, SubRegion)));
+ }
+
+ ~RegionStoreSubRegionMap() {}
+
+ void iterSubRegions(const MemRegion* Parent, Visitor& V) const {
+ Map::iterator I = M.find(Parent);
+
+ if (I == M.end())
+ return;
+
+ llvm::ImmutableSet<const MemRegion*> S = I->second;
+ for (llvm::ImmutableSet<const MemRegion*>::iterator SI=S.begin(),SE=S.end();
+ SI != SE; ++SI) {
+ if (!V.Visit(Parent, *SI))
+ return;
+ }
+ }
+};
+
class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
RegionBindingsTy::Factory RBFactory;
RegionViews::Factory RVFactory;
@@ -128,6 +159,8 @@
MemRegionManager& getRegionManager() { return MRMgr; }
+ std::auto_ptr<SubRegionMap> getSubRegionMap(const GRState *state);
+
const GRState* BindCompoundLiteral(const GRState* St,
const CompoundLiteralExpr* CL, SVal V);
@@ -268,6 +301,18 @@
return new RegionStoreManager(StMgr);
}
+std::auto_ptr<SubRegionMap>
+RegionStoreManager::getSubRegionMap(const GRState *state) {
+ RegionBindingsTy B = GetRegionBindings(state->getStore());
+ RegionStoreSubRegionMap *M = new RegionStoreSubRegionMap();
+
+ for (RegionBindingsTy::iterator I=B.begin(), E=B.end(); I!=E; ++I) {
+ if (const SubRegion* R = dyn_cast<SubRegion>(I.getKey()))
+ M->add(R->getSuperRegion(), R);
+ }
+
+ return std::auto_ptr<SubRegionMap>(M);
+}
/// getLValueString - Returns an SVal representing the lvalue of a
/// StringLiteral. Within RegionStore a StringLiteral has an
More information about the cfe-commits
mailing list