namespace clang {
class MemRegionManager;
-
+class MemSpaceRegion;
/// MemRegion - The root abstract class for all memory regions.
class MemRegion : public llvm::FoldingSetNode {
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;
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.