summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-03-05 16:31:07 +0000
committerTed Kremenek <kremenek@apple.com>2009-03-05 16:31:07 +0000
commit2f340d6cb66ebeea59f27a5c576bc14bfdebad5d (patch)
treecd68d6a95af2bce3796198c8deb0c6496224e51d
parent8f4528bc7c670bf46db9f76ae4a25b6e39da06b4 (diff)
downloadbcm5719-llvm-2f340d6cb66ebeea59f27a5c576bc14bfdebad5d.tar.gz
bcm5719-llvm-2f340d6cb66ebeea59f27a5c576bc14bfdebad5d.zip
BasicStore:
- Store bindings using a MemRegion -> SVal binding instead of VarDecl -> SVal binding. This mirrors some of the idea of RegionStore, but is far simpler and not nearly as functional. This leads to some code simplification and some potential for some minor precision hacks. Along the way... - constify the use of MemRegion* in a few places - add operator<<(llvm::raw_ostream, const MemRegion*) llvm-svn: 66163
-rw-r--r--clang/include/clang/Analysis/PathSensitive/MemRegion.h12
-rw-r--r--clang/include/clang/Analysis/PathSensitive/Store.h2
-rw-r--r--clang/lib/Analysis/BasicStore.cpp30
-rw-r--r--clang/lib/Analysis/BugReporter.cpp6
-rw-r--r--clang/lib/Analysis/CFRefCount.cpp7
5 files changed, 34 insertions, 23 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/MemRegion.h b/clang/include/clang/Analysis/PathSensitive/MemRegion.h
index 2ddaa20d327..3c9d705176b 100644
--- a/clang/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/clang/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -543,9 +543,15 @@ public:
private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
-};
+};
+} // end clang namespace
+namespace llvm {
+static inline raw_ostream& operator<<(raw_ostream& O,
+ const clang::MemRegion* R) {
+ R->print(O);
+ return O;
+}
+} // end llvm namespace
-
-} // end clang namespace
#endif
diff --git a/clang/include/clang/Analysis/PathSensitive/Store.h b/clang/include/clang/Analysis/PathSensitive/Store.h
index 4514de752df..c52f389370d 100644
--- a/clang/include/clang/Analysis/PathSensitive/Store.h
+++ b/clang/include/clang/Analysis/PathSensitive/Store.h
@@ -156,7 +156,7 @@ public:
public:
virtual ~BindingsHandler();
virtual bool HandleBinding(StoreManager& SMgr, Store store,
- MemRegion* R, SVal val) = 0;
+ const MemRegion* R, SVal val) = 0;
};
/// iterBindings - Iterate over the bindings in the Store.
diff --git a/clang/lib/Analysis/BasicStore.cpp b/clang/lib/Analysis/BasicStore.cpp
index 2e619baf2f4..edc27680355 100644
--- a/clang/lib/Analysis/BasicStore.cpp
+++ b/clang/lib/Analysis/BasicStore.cpp
@@ -19,7 +19,7 @@
using namespace clang;
-typedef llvm::ImmutableMap<const VarDecl*,SVal> VarBindingsTy;
+typedef llvm::ImmutableMap<const MemRegion*,SVal> VarBindingsTy;
namespace {
@@ -307,7 +307,7 @@ SVal BasicStoreManager::Retrieve(const GRState* state, Loc loc, QualType T) {
Store store = state->getStore();
VarBindingsTy B = GetVarBindings(store);
- VarBindingsTy::data_type* T = B.lookup(R->getDecl());
+ VarBindingsTy::data_type* T = B.lookup(R);
return T ? *T : UnknownVal();
}
@@ -341,8 +341,8 @@ Store BasicStoreManager::BindInternal(Store store, Loc loc, SVal V) {
VarBindingsTy B = GetVarBindings(store);
return V.isUnknown()
- ? VBFactory.Remove(B, R->getDecl()).getRoot()
- : VBFactory.Add(B, R->getDecl(), V).getRoot();
+ ? VBFactory.Remove(B, R).getRoot()
+ : VBFactory.Add(B, R, V).getRoot();
}
default:
assert ("SetSVal for given Loc type not yet implemented.");
@@ -360,7 +360,7 @@ Store BasicStoreManager::Remove(Store store, Loc loc) {
return store;
VarBindingsTy B = GetVarBindings(store);
- return VBFactory.Remove(B,R->getDecl()).getRoot();
+ return VBFactory.Remove(B, R).getRoot();
}
default:
assert ("Remove for given Loc type not yet implemented.");
@@ -379,14 +379,16 @@ BasicStoreManager::RemoveDeadBindings(const GRState* state, Stmt* Loc,
typedef SVal::symbol_iterator symbol_iterator;
// Iterate over the variable bindings.
- for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I)
- if (SymReaper.isLive(Loc, I.getKey())) {
- RegionRoots.push_back(MRMgr.getVarRegion(I.getKey()));
+ for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) {
+ const VarRegion *VR = cast<VarRegion>(I.getKey());
+ if (SymReaper.isLive(Loc, VR->getDecl())) {
+ RegionRoots.push_back(VR);
SVal X = I.getData();
for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
SymReaper.markLive(*SI);
}
+ }
// Scan for live variables and live symbols.
llvm::SmallPtrSet<const VarRegion*, 10> Marked;
@@ -427,7 +429,7 @@ BasicStoreManager::RemoveDeadBindings(const GRState* state, Stmt* Loc,
// Remove dead variable bindings.
for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) {
- const VarRegion* R = cast<VarRegion>(MRMgr.getVarRegion(I.getKey()));
+ const VarRegion* R = cast<VarRegion>(I.getKey());
if (!Marked.count(R)) {
store = Remove(store, Loc::MakeVal(R));
@@ -548,9 +550,10 @@ Store BasicStoreManager::BindDeclInternal(Store store, const VarDecl* VD,
return store;
}
-void BasicStoreManager::print(Store store, std::ostream& Out,
+void BasicStoreManager::print(Store store, std::ostream& O,
const char* nl, const char *sep) {
+ llvm::raw_os_ostream Out(O);
VarBindingsTy B = GetVarBindings(store);
Out << "Variables:" << nl;
@@ -560,7 +563,7 @@ void BasicStoreManager::print(Store store, std::ostream& Out,
if (isFirst) isFirst = false;
else Out << nl;
- Out << ' ' << I.getKey()->getNameAsString() << " : ";
+ Out << ' ' << I.getKey() << " : ";
I.getData().print(Out);
}
}
@@ -569,10 +572,9 @@ void BasicStoreManager::print(Store store, std::ostream& Out,
void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) {
VarBindingsTy B = GetVarBindings(store);
- for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) {
+ for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I)
+ f.HandleBinding(*this, store, I.getKey(), I.getData());
- f.HandleBinding(*this, store, MRMgr.getVarRegion(I.getKey()),I.getData());
- }
}
StoreManager::BindingsHandler::~BindingsHandler() {}
diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp
index e1265ded171..88887b1d6c7 100644
--- a/clang/lib/Analysis/BugReporter.cpp
+++ b/clang/lib/Analysis/BugReporter.cpp
@@ -419,7 +419,8 @@ public:
PathDiagnostic& pd, BugReporter& br)
: Sym(sym), PrevSt(prevst), S(s), VMgr(vmgr), Pred(pred), PD(pd), BR(br) {}
- bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal V) {
+ bool HandleBinding(StoreManager& SMgr, Store store,
+ const MemRegion* R, SVal V) {
SymbolRef ScanSym;
@@ -521,7 +522,8 @@ public:
PathDiagnostic& pd)
: N(n), S(s), BR(br), PD(pd) {}
- bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal V) {
+ bool HandleBinding(StoreManager& SMgr, Store store,
+ const MemRegion* R, SVal V) {
SymbolRef ScanSym;
if (loc::SymbolVal* SV = dyn_cast<loc::SymbolVal>(&V))
diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp
index 6929af32f93..8c3d9bf366f 100644
--- a/clang/lib/Analysis/CFRefCount.cpp
+++ b/clang/lib/Analysis/CFRefCount.cpp
@@ -2663,13 +2663,14 @@ namespace {
class VISIBILITY_HIDDEN FindUniqueBinding :
public StoreManager::BindingsHandler {
SymbolRef Sym;
- MemRegion* Binding;
+ const MemRegion* Binding;
bool First;
public:
FindUniqueBinding(SymbolRef sym) : Sym(sym), Binding(0), First(true) {}
- bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal val) {
+ bool HandleBinding(StoreManager& SMgr, Store store, const MemRegion* R,
+ SVal val) {
SymbolRef SymV = val.getAsSymbol();
if (!SymV.isValid() || SymV != Sym)
@@ -2686,7 +2687,7 @@ class VISIBILITY_HIDDEN FindUniqueBinding :
}
operator bool() { return First && Binding; }
- MemRegion* getRegion() { return Binding; }
+ const MemRegion* getRegion() { return Binding; }
};
}
OpenPOWER on IntegriCloud