[cfe-commits] r73977 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp lib/Analysis/RegionStore.cpp
Ted Kremenek
kremenek at apple.com
Tue Jun 23 11:17:09 PDT 2009
Author: kremenek
Date: Tue Jun 23 13:17:08 2009
New Revision: 73977
URL: http://llvm.org/viewvc/llvm-project?rev=73977&view=rev
Log:
- 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()'.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
cfe/trunk/lib/Analysis/MemRegion.cpp
cfe/trunk/lib/Analysis/RegionStore.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=73977&r1=73976&r2=73977&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Tue Jun 23 13:17:08 2009
@@ -33,7 +33,7 @@
namespace clang {
class MemRegionManager;
-
+class MemSpaceRegion;
/// MemRegion - The root abstract class for all memory regions.
class MemRegion : public llvm::FoldingSetNode {
@@ -68,10 +68,14 @@
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;
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=73977&r1=73976&r2=73977&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Tue Jun 23 13:17:08 2009
@@ -313,45 +313,40 @@
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.
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=73977&r1=73976&r2=73977&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Tue Jun 23 13:17:08 2009
@@ -939,7 +939,7 @@
}
}
- 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
More information about the cfe-commits
mailing list