aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-07-29 18:14:27 +0000
committerTed Kremenek <kremenek@apple.com>2009-07-29 18:14:27 +0000
commit0e3ec3ff2477e60f0ceda922cc2e3a25a59d81f2 (patch)
tree192fdbada0d27ec818dafaf7f32bb1d634d5e2f5
parent4e6e0d70e759bad13a36809b23fd7205c9cc1f91 (diff)
Add 'MemRegion::getBaseRegion()', a utility method to strip ElementRegions with
index 0. This will be used for refinements to InvalidateRegion and CastRegion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77481 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/MemRegion.h2
-rw-r--r--include/clang/Analysis/PathSensitive/SVals.h2
-rw-r--r--lib/Analysis/MemRegion.cpp20
-rw-r--r--lib/Analysis/SVals.cpp8
4 files changed, 30 insertions, 2 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h
index bcd195e75e..a65c71b5ec 100644
--- a/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -70,6 +70,8 @@ public:
std::string getString() const;
const MemSpaceRegion *getMemorySpace() const;
+
+ const MemRegion *getBaseRegion() const;
bool hasStackStorage() const;
diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h
index 2ba370e532..63110c6fac 100644
--- a/include/clang/Analysis/PathSensitive/SVals.h
+++ b/include/clang/Analysis/PathSensitive/SVals.h
@@ -371,6 +371,8 @@ public:
return static_cast<MemRegion*>(Data);
}
+ const MemRegion* getBaseRegion() const;
+
template <typename REGION>
const REGION* getRegionAs() const {
return llvm::dyn_cast<REGION>(getRegion());
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 9b8f7c81e1..a708bd3068 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -398,3 +398,23 @@ const MemRegion *TypedViewRegion::removeViews() const {
}
return R;
}
+
+const MemRegion *MemRegion::getBaseRegion() const {
+ const MemRegion *R = this;
+ while (true) {
+ if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) {
+ // FIXME: generalize. Essentially we want to strip away ElementRegions
+ // that were layered on a symbolic region because of casts. We only
+ // want to strip away ElementRegions, however, where the index is 0.
+ SVal index = ER->getIndex();
+ if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&index)) {
+ if (CI->getValue().getZExtValue() == 0) {
+ R = ER->getSuperRegion();
+ continue;
+ }
+ }
+ }
+ break;
+ }
+ return R;
+}
diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp
index a5ba199398..6f480e8d46 100644
--- a/lib/Analysis/SVals.cpp
+++ b/lib/Analysis/SVals.cpp
@@ -72,7 +72,7 @@ const FunctionDecl* SVal::getAsFunctionDecl() const {
// FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
SymbolRef SVal::getAsLocSymbol() const {
if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) {
- const MemRegion *R = X->getRegion();
+ const MemRegion *R = X->getBaseRegion();
while (R) {
// Blast through region views.
@@ -80,7 +80,6 @@ SymbolRef SVal::getAsLocSymbol() const {
R = View->getSuperRegion();
continue;
}
-
if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
return SymR->getSymbol();
@@ -121,6 +120,11 @@ const MemRegion *SVal::getAsRegion() const {
return 0;
}
+const MemRegion *loc::MemRegionVal::getBaseRegion() const {
+ const MemRegion *R = getRegion();
+ return R ? R->getBaseRegion() : NULL;
+}
+
bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const {
return itr == X.itr;
}