aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-06-23 18:17:08 +0000
committerTed Kremenek <kremenek@apple.com>2009-06-23 18:17:08 +0000
commitbb7c96f290453104ec35ca17111a5165f68a4697 (patch)
treeccfc2ca389e182bf11d1bc04f99a8f3f3a1e5df6
parent3c092bce5fb4523854c3429e0af44f99c6fe2b92 (diff)
- Add MemRegion::getMemorySpace()
- Change implementation of MemRegion::hasStackStorage()/hasHeapStorage() to use 'getMemorySpace()'. This avoids a double traversal up the region hierarchy and is simpler. - Add MemRegion::hasHeapOrStackStorage() as a slightly more efficient alternative to 'hasStackStorage() || hasHeapStorage()'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73977 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/MemRegion.h6
-rw-r--r--lib/Analysis/MemRegion.cpp49
-rw-r--r--lib/Analysis/RegionStore.cpp2
3 files changed, 28 insertions, 29 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h
index b531375be2..65ac0b5302 100644
--- a/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -33,7 +33,7 @@ namespace llvm { class raw_ostream; }
namespace clang {
class MemRegionManager;
-
+class MemSpaceRegion;
/// MemRegion - The root abstract class for all memory regions.
class MemRegion : public llvm::FoldingSetNode {
@@ -68,10 +68,14 @@ public:
virtual MemRegionManager* getMemRegionManager() const = 0;
std::string getString() const;
+
+ const MemSpaceRegion *getMemorySpace() const;
bool hasStackStorage() const;
bool hasHeapStorage() const;
+
+ bool hasHeapOrStackStorage() const;
virtual void print(llvm::raw_ostream& os) const;
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index f018c83b91..c8e027579a 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -313,45 +313,40 @@ AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
return getRegion<AllocaRegion>(E, cnt);
}
-bool MemRegion::hasStackStorage() const {
- // Only subregions can have stack storage.
- const SubRegion* SR = dyn_cast<SubRegion>(this);
-
- if (!SR)
- return false;
- MemSpaceRegion* S = getMemRegionManager()->getStackRegion();
+const MemSpaceRegion *MemRegion::getMemorySpace() const {
+ const MemRegion *R = this;
+ const SubRegion* SR = dyn_cast<SubRegion>(this);
while (SR) {
- const MemRegion *R = SR->getSuperRegion();
- if (R == S)
- return true;
-
- SR = dyn_cast<SubRegion>(R);
+ R = SR->getSuperRegion();
+ SR = dyn_cast<SubRegion>(R);
}
-
- return false;
+
+ return dyn_cast<MemSpaceRegion>(R);
}
-bool MemRegion::hasHeapStorage() const {
- // Only subregions can have stack storage.
- const SubRegion* SR = dyn_cast<SubRegion>(this);
+bool MemRegion::hasStackStorage() const {
+ if (const MemSpaceRegion *MS = getMemorySpace())
+ return MS == getMemRegionManager()->getStackRegion();
- if (!SR)
- return false;
+ return false;
+}
- MemSpaceRegion* H = getMemRegionManager()->getHeapRegion();
+bool MemRegion::hasHeapStorage() const {
+ if (const MemSpaceRegion *MS = getMemorySpace())
+ return MS == getMemRegionManager()->getHeapRegion();
- while (SR) {
- const MemRegion *R = SR->getSuperRegion();
- if (R == H)
- return true;
+ return false;
+}
- SR = dyn_cast<SubRegion>(R);
+bool MemRegion::hasHeapOrStackStorage() const {
+ if (const MemSpaceRegion *MS = getMemorySpace()) {
+ MemRegionManager *Mgr = getMemRegionManager();
+ return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion();
}
-
return false;
-}
+}
//===----------------------------------------------------------------------===//
// View handling.
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 17e332387f..77f5b7cb39 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -939,7 +939,7 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) {
}
}
- if (R->hasStackStorage() || R->hasHeapStorage()) {
+ if (R->hasHeapOrStackStorage()) {
// All stack variables are considered to have undefined values
// upon creation. All heap allocated blocks are considered to
// have undefined values as well unless they are explicitly bound