[cfe-commits] r74729 - in /cfe/trunk: lib/Analysis/MemRegion.cpp lib/Analysis/RegionStore.cpp test/Analysis/stack-addr-ps.c
Ted Kremenek
kremenek at apple.com
Thu Jul 2 15:02:15 PDT 2009
Author: kremenek
Date: Thu Jul 2 17:02:15 2009
New Revision: 74729
URL: http://llvm.org/viewvc/llvm-project?rev=74729&view=rev
Log:
Enhance RegionStore to lazily symbolicate fields and array elements for
structures passed-by-value as function arguments.
Modified:
cfe/trunk/lib/Analysis/MemRegion.cpp
cfe/trunk/lib/Analysis/RegionStore.cpp
cfe/trunk/test/Analysis/stack-addr-ps.c
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=74729&r1=74728&r2=74729&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Thu Jul 2 17:02:15 2009
@@ -368,6 +368,13 @@
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();
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=74729&r1=74728&r2=74729&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Thu Jul 2 17:02:15 2009
@@ -959,7 +959,7 @@
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 @@
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
Modified: cfe/trunk/test/Analysis/stack-addr-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/stack-addr-ps.c?rev=74729&r1=74728&r2=74729&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/stack-addr-ps.c (original)
+++ cfe/trunk/test/Analysis/stack-addr-ps.c Thu Jul 2 17:02:15 2009
@@ -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 @@
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
+ }
}
-
More information about the cfe-commits
mailing list