aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/MemRegion.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-12-11 06:43:27 +0000
committerTed Kremenek <kremenek@apple.com>2009-12-11 06:43:27 +0000
commit2b87ae45e129b941d0a4d221c9d4842385a119bd (patch)
tree25d052be3aaf688c995b9292988d2fe4a8a125cd /lib/Analysis/MemRegion.cpp
parenta49c6b7da5684e061612de70b62fe892b67f35c4 (diff)
Enhance understanding of VarRegions referenced by a block whose declarations are outside the current stack frame. Fixes <rdar://problem/7462324>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemRegion.cpp')
-rw-r--r--lib/Analysis/MemRegion.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 3bf3e5b28a..da45c4dfee 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -381,13 +381,22 @@ const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
}
const StackLocalsSpaceRegion*
-MemRegionManager::getStackLocalsRegion(const StackFrameContext *STC) {
- return LazyAllocate(stackLocals, STC);
+MemRegionManager::getStackLocalsRegion(const StackFrameContext *STC) {
+ assert(STC);
+ if (STC == cachedStackLocalsFrame)
+ return cachedStackLocalsRegion;
+ cachedStackLocalsFrame = STC;
+ return LazyAllocate(cachedStackLocalsRegion, STC);
}
const StackArgumentsSpaceRegion *
MemRegionManager::getStackArgumentsRegion(const StackFrameContext *STC) {
- return LazyAllocate(stackArguments, STC);
+ assert(STC);
+ if (STC == cachedStackArgumentsFrame)
+ return cachedStackArgumentsRegion;
+
+ cachedStackArgumentsFrame = STC;
+ return LazyAllocate(cachedStackArgumentsRegion, STC);
}
const GlobalsSpaceRegion *MemRegionManager::getGlobalsRegion() {
@@ -418,15 +427,19 @@ const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D,
const LocationContext *LC) {
const MemRegion *sReg = 0;
- if (D->hasLocalStorage()) {
+ if (D->hasLocalStorage()) {
// FIXME: Once we implement scope handling, we will need to properly lookup
// 'D' to the proper LocationContext.
- const StackFrameContext *STC = LC->getCurrentStackFrame();
+ const DeclContext *DC = D->getDeclContext();
+ const StackFrameContext *STC = LC->getStackFrameForDeclContext(DC);
- assert(STC);
- sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
- ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC))
- : static_cast<const MemRegion*>(getStackLocalsRegion(STC));
+ if (!STC)
+ sReg = getUnknownRegion();
+ else {
+ sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
+ ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC))
+ : static_cast<const MemRegion*>(getStackLocalsRegion(STC));
+ }
}
else {
sReg = getGlobalsRegion();