forked from OSchip/llvm-project
				
			- 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:
		
							parent
							
								
									e14d93c49e
								
							
						
					
					
						commit
						2d99f97c17
					
				| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -69,10 +69,14 @@ public:
 | 
			
		|||
 | 
			
		||||
  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;  
 | 
			
		||||
  
 | 
			
		||||
  Kind getKind() const { return kind; }  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -313,43 +313,38 @@ AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned 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);
 | 
			
		||||
  
 | 
			
		||||
  if (!SR)
 | 
			
		||||
    return false;
 | 
			
		||||
 | 
			
		||||
  MemSpaceRegion* S = getMemRegionManager()->getStackRegion();
 | 
			
		||||
  
 | 
			
		||||
  while (SR) {
 | 
			
		||||
    const MemRegion *R = SR->getSuperRegion();
 | 
			
		||||
    if (R == S)
 | 
			
		||||
      return true;
 | 
			
		||||
    
 | 
			
		||||
    R = SR->getSuperRegion();
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool MemRegion::hasHeapStorage() const {
 | 
			
		||||
  // Only subregions can have stack storage.
 | 
			
		||||
  const SubRegion* SR = dyn_cast<SubRegion>(this);
 | 
			
		||||
  if (const MemSpaceRegion *MS = getMemorySpace())
 | 
			
		||||
    return MS == getMemRegionManager()->getHeapRegion();
 | 
			
		||||
 | 
			
		||||
  if (!SR)
 | 
			
		||||
    return false;
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  MemSpaceRegion* H = getMemRegionManager()->getHeapRegion();
 | 
			
		||||
 | 
			
		||||
  while (SR) {
 | 
			
		||||
    const MemRegion *R = SR->getSuperRegion();
 | 
			
		||||
    if (R == H)
 | 
			
		||||
      return true;
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue