- 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()'.

llvm-svn: 73977
This commit is contained in:
Ted Kremenek 2009-06-23 18:17:08 +00:00
parent e14d93c49e
commit 2d99f97c17
3 changed files with 29 additions and 30 deletions

View File

@ -33,7 +33,7 @@ namespace llvm { class raw_ostream; }
namespace clang { namespace clang {
class MemRegionManager; class MemRegionManager;
class MemSpaceRegion;
/// MemRegion - The root abstract class for all memory regions. /// MemRegion - The root abstract class for all memory regions.
class MemRegion : public llvm::FoldingSetNode { class MemRegion : public llvm::FoldingSetNode {
@ -68,10 +68,14 @@ public:
virtual MemRegionManager* getMemRegionManager() const = 0; virtual MemRegionManager* getMemRegionManager() const = 0;
std::string getString() const; std::string getString() const;
const MemSpaceRegion *getMemorySpace() const;
bool hasStackStorage() const; bool hasStackStorage() const;
bool hasHeapStorage() const; bool hasHeapStorage() const;
bool hasHeapOrStackStorage() const;
virtual void print(llvm::raw_ostream& os) const; virtual void print(llvm::raw_ostream& os) const;

View File

@ -313,46 +313,41 @@ AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
return getRegion<AllocaRegion>(E, cnt); return getRegion<AllocaRegion>(E, cnt);
} }
bool MemRegion::hasStackStorage() const {
// Only subregions can have stack storage. const MemSpaceRegion *MemRegion::getMemorySpace() const {
const MemRegion *R = this;
const SubRegion* SR = dyn_cast<SubRegion>(this); const SubRegion* SR = dyn_cast<SubRegion>(this);
if (!SR)
return false;
MemSpaceRegion* S = getMemRegionManager()->getStackRegion();
while (SR) { while (SR) {
const MemRegion *R = SR->getSuperRegion(); R = SR->getSuperRegion();
if (R == S) SR = dyn_cast<SubRegion>(R);
return true;
SR = dyn_cast<SubRegion>(R);
} }
return dyn_cast<MemSpaceRegion>(R);
}
bool MemRegion::hasStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace())
return MS == getMemRegionManager()->getStackRegion();
return false; return false;
} }
bool MemRegion::hasHeapStorage() const { bool MemRegion::hasHeapStorage() const {
// Only subregions can have stack storage. if (const MemSpaceRegion *MS = getMemorySpace())
const SubRegion* SR = dyn_cast<SubRegion>(this); return MS == getMemRegionManager()->getHeapRegion();
if (!SR)
return false;
MemSpaceRegion* H = getMemRegionManager()->getHeapRegion();
while (SR) {
const MemRegion *R = SR->getSuperRegion();
if (R == H)
return true;
SR = dyn_cast<SubRegion>(R);
}
return false; return false;
} }
bool MemRegion::hasHeapOrStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace()) {
MemRegionManager *Mgr = getMemRegionManager();
return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion();
}
return false;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// View handling. // View handling.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -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 // All stack variables are considered to have undefined values
// upon creation. All heap allocated blocks are considered to // upon creation. All heap allocated blocks are considered to
// have undefined values as well unless they are explicitly bound // have undefined values as well unless they are explicitly bound