diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-07-02 22:02:15 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-07-02 22:02:15 +0000 |
commit | dc147262b1ea0636cf8e7152f19303042dffdbed (patch) | |
tree | b922bba47fa63d08a8f902753f5c009b9f8716c0 | |
parent | 41e8c21eb41fca41e2e065e75f01433427858c19 (diff) |
Enhance RegionStore to lazily symbolicate fields and array elements for
structures passed-by-value as function arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74729 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/MemRegion.cpp | 7 | ||||
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 8 | ||||
-rw-r--r-- | test/Analysis/stack-addr-ps.c | 21 |
3 files changed, 26 insertions, 10 deletions
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 52e26238d9..4530540358 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -368,6 +368,13 @@ bool MemRegion::hasGlobalsStorage() const { return false; } +bool MemRegion::hasParametersStorage() const { + if (const MemSpaceRegion *MS = getMemorySpace()) + return MS == getMemRegionManager()->getStackArgumentsRegion(); + + return false; +} + bool MemRegion::hasGlobalsOrParametersStorage() const { if (const MemSpaceRegion *MS = getMemorySpace()) { MemRegionManager *Mgr = getMemRegionManager(); diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 9c76265fa3..5729103fd3 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -959,7 +959,7 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state, return UndefinedVal(); } - if (R->hasStackStorage()) { + if (R->hasStackStorage() && !R->hasParametersStorage()) { // Currently we don't reason specially about Clang-style vectors. Check // if superR is a vector and if so return Unknown. if (const TypedRegion *typedSuperR = dyn_cast<TypedRegion>(superR)) { @@ -1006,7 +1006,11 @@ SVal RegionStoreManager::RetrieveField(const GRState* state, assert(0 && "Unknown default value"); } - if (R->hasHeapOrStackStorage()) + // FIXME: Is this correct? Should it be UnknownVal? + if (R->hasHeapStorage()) + return UndefinedVal(); + + if (R->hasStackStorage() && !R->hasParametersStorage()) return UndefinedVal(); // If the region is already cast to another type, use that type to create the diff --git a/test/Analysis/stack-addr-ps.c b/test/Analysis/stack-addr-ps.c index 848adc8d9f..0d7a70373c 100644 --- a/test/Analysis/stack-addr-ps.c +++ b/test/Analysis/stack-addr-ps.c @@ -1,6 +1,5 @@ -// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s - -// NOWORK: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s +// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s && +// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s #include <stdlib.h> @@ -46,9 +45,15 @@ int array_test(int x[2]) { return x[0]; // no-warning } -struct baz { int x; }; - -int struct_test(struct baz byVal) { - return byVal.x; // no-warning; +struct baz { + int x; + int y[2]; +}; + +int struct_test(struct baz byVal, int flag) { + if (flag) + return byVal.x; // no-warning + else { + return byVal.y[0]; // no-warning + } } - |