From: Ted Kremenek Date: Thu, 2 Jul 2009 18:14:59 +0000 (+0000) Subject: Add a separate MemSpaceRegion for function/method arguments passed on the stack. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d05552a21377f493c882298c59e8829040b01d34;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74715 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 115411985c..432702c089 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -583,15 +583,17 @@ class MemRegionManager { llvm::BumpPtrAllocator& A; llvm::FoldingSet Regions; - MemSpaceRegion* globals; - MemSpaceRegion* stack; - MemSpaceRegion* heap; - MemSpaceRegion* unknown; - MemSpaceRegion* code; + MemSpaceRegion *globals; + MemSpaceRegion *stack; + MemSpaceRegion *stackArguments; + MemSpaceRegion *heap; + MemSpaceRegion *unknown; + MemSpaceRegion *code; public: 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() {} @@ -599,24 +601,28 @@ public: /// getStackRegion - Retrieve the memory region associated with the /// 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 /// all global variables. - MemSpaceRegion* getGlobalsRegion(); + MemSpaceRegion *getGlobalsRegion(); /// getHeapRegion - Retrieve the memory region associated with the /// generic "heap". - MemSpaceRegion* getHeapRegion(); + MemSpaceRegion *getHeapRegion(); /// getUnknownRegion - Retrieve the memory region associated with unknown /// memory space. - MemSpaceRegion* getUnknownRegion(); + MemSpaceRegion *getUnknownRegion(); - MemSpaceRegion* getCodeRegion(); + MemSpaceRegion *getCodeRegion(); /// 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 /// given CompoundLiteral. @@ -784,8 +790,12 @@ template <> struct MemRegionManagerTrait { typedef MemRegion SuperRegionTy; static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr, const VarDecl *d) { - return d->hasLocalStorage() ? MRMgr.getStackRegion() - : MRMgr.getGlobalsRegion(); + if (d->hasLocalStorage()) { + return isa(d) || isa(d) + ? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion(); + } + + return MRMgr.getGlobalsRegion(); } }; diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 98b4cf9eb4..9314b1ec77 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -223,6 +223,10 @@ MemSpaceRegion* MemRegionManager::getStackRegion() { return LazyAllocate(stack); } +MemSpaceRegion* MemRegionManager::getStackArgumentsRegion() { + return LazyAllocate(stackArguments); +} + MemSpaceRegion* MemRegionManager::getGlobalsRegion() { return LazyAllocate(globals); } @@ -332,8 +336,10 @@ const MemSpaceRegion *MemRegion::getMemorySpace() const { } bool MemRegion::hasStackStorage() const { - if (const MemSpaceRegion *MS = getMemorySpace()) - return MS == getMemRegionManager()->getStackRegion(); + if (const MemSpaceRegion *MS = getMemorySpace()) { + MemRegionManager *Mgr = getMemRegionManager(); + return MS == Mgr->getStackRegion() || MS == Mgr->getStackArgumentsRegion(); + } return false; } @@ -348,7 +354,9 @@ bool MemRegion::hasHeapStorage() const { bool MemRegion::hasHeapOrStackStorage() const { if (const MemSpaceRegion *MS = getMemorySpace()) { MemRegionManager *Mgr = getMemRegionManager(); - return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion(); + return MS == Mgr->getHeapRegion() + || MS == Mgr->getStackRegion() + || MS == Mgr->getStackArgumentsRegion(); } return false; }