Add a separate MemSpaceRegion for function/method arguments passed on the stack.

This will simplify the logic of StoreManagers that want to specially reason
about the values of parameters.

llvm-svn: 74715
This commit is contained in:
Ted Kremenek 2009-07-02 18:14:59 +00:00
parent 0a2c458ae0
commit 7e4a9a02c3
2 changed files with 35 additions and 17 deletions

View File

@ -583,15 +583,17 @@ class MemRegionManager {
llvm::BumpPtrAllocator& A; llvm::BumpPtrAllocator& A;
llvm::FoldingSet<MemRegion> Regions; llvm::FoldingSet<MemRegion> Regions;
MemSpaceRegion* globals; MemSpaceRegion *globals;
MemSpaceRegion* stack; MemSpaceRegion *stack;
MemSpaceRegion* heap; MemSpaceRegion *stackArguments;
MemSpaceRegion* unknown; MemSpaceRegion *heap;
MemSpaceRegion* code; MemSpaceRegion *unknown;
MemSpaceRegion *code;
public: public:
MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator& a) MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator& a)
: C(c), A(a), globals(0), stack(0), heap(0), unknown(0), code(0) {} : C(c), A(a), globals(0), stack(0), stackArguments(0), heap(0),
unknown(0), code(0) {}
~MemRegionManager() {} ~MemRegionManager() {}
@ -599,24 +601,28 @@ public:
/// getStackRegion - Retrieve the memory region associated with the /// getStackRegion - Retrieve the memory region associated with the
/// current stack frame. /// current stack frame.
MemSpaceRegion* getStackRegion(); MemSpaceRegion *getStackRegion();
/// getStackArgumentsRegion - Retrieve the memory region associated with
/// function/method arguments of the current stack frame.
MemSpaceRegion *getStackArgumentsRegion();
/// getGlobalsRegion - Retrieve the memory region associated with /// getGlobalsRegion - Retrieve the memory region associated with
/// all global variables. /// all global variables.
MemSpaceRegion* getGlobalsRegion(); MemSpaceRegion *getGlobalsRegion();
/// getHeapRegion - Retrieve the memory region associated with the /// getHeapRegion - Retrieve the memory region associated with the
/// generic "heap". /// generic "heap".
MemSpaceRegion* getHeapRegion(); MemSpaceRegion *getHeapRegion();
/// getUnknownRegion - Retrieve the memory region associated with unknown /// getUnknownRegion - Retrieve the memory region associated with unknown
/// memory space. /// memory space.
MemSpaceRegion* getUnknownRegion(); MemSpaceRegion *getUnknownRegion();
MemSpaceRegion* getCodeRegion(); MemSpaceRegion *getCodeRegion();
/// getAllocaRegion - Retrieve a region associated with a call to alloca(). /// getAllocaRegion - Retrieve a region associated with a call to alloca().
AllocaRegion* getAllocaRegion(const Expr* Ex, unsigned Cnt); AllocaRegion *getAllocaRegion(const Expr* Ex, unsigned Cnt);
/// getCompoundLiteralRegion - Retrieve the region associated with a /// getCompoundLiteralRegion - Retrieve the region associated with a
/// given CompoundLiteral. /// given CompoundLiteral.
@ -784,8 +790,12 @@ template <> struct MemRegionManagerTrait<VarRegion> {
typedef MemRegion SuperRegionTy; typedef MemRegion SuperRegionTy;
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr, static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
const VarDecl *d) { const VarDecl *d) {
return d->hasLocalStorage() ? MRMgr.getStackRegion() if (d->hasLocalStorage()) {
: MRMgr.getGlobalsRegion(); return isa<ParmVarDecl>(d) || isa<ImplicitParamDecl>(d)
? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion();
}
return MRMgr.getGlobalsRegion();
} }
}; };

View File

@ -223,6 +223,10 @@ MemSpaceRegion* MemRegionManager::getStackRegion() {
return LazyAllocate(stack); return LazyAllocate(stack);
} }
MemSpaceRegion* MemRegionManager::getStackArgumentsRegion() {
return LazyAllocate(stackArguments);
}
MemSpaceRegion* MemRegionManager::getGlobalsRegion() { MemSpaceRegion* MemRegionManager::getGlobalsRegion() {
return LazyAllocate(globals); return LazyAllocate(globals);
} }
@ -332,8 +336,10 @@ const MemSpaceRegion *MemRegion::getMemorySpace() const {
} }
bool MemRegion::hasStackStorage() const { bool MemRegion::hasStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace()) if (const MemSpaceRegion *MS = getMemorySpace()) {
return MS == getMemRegionManager()->getStackRegion(); MemRegionManager *Mgr = getMemRegionManager();
return MS == Mgr->getStackRegion() || MS == Mgr->getStackArgumentsRegion();
}
return false; return false;
} }
@ -348,7 +354,9 @@ bool MemRegion::hasHeapStorage() const {
bool MemRegion::hasHeapOrStackStorage() const { bool MemRegion::hasHeapOrStackStorage() const {
if (const MemSpaceRegion *MS = getMemorySpace()) { if (const MemSpaceRegion *MS = getMemorySpace()) {
MemRegionManager *Mgr = getMemRegionManager(); MemRegionManager *Mgr = getMemRegionManager();
return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion(); return MS == Mgr->getHeapRegion()
|| MS == Mgr->getStackRegion()
|| MS == Mgr->getStackArgumentsRegion();
} }
return false; return false;
} }