diff options
| author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-01-23 11:22:12 +0000 |
|---|---|---|
| committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-01-23 11:22:12 +0000 |
| commit | e37f9afb2ea832ecbabf2513da899bf38273e6f2 (patch) | |
| tree | 9ce2dcae4782ed77adec561996e85f9de6994e39 | |
| parent | 804f26a60a79ceb4b92fca44c519effb0b7956f4 (diff) | |
| download | bcm5719-llvm-e37f9afb2ea832ecbabf2513da899bf38273e6f2.tar.gz bcm5719-llvm-e37f9afb2ea832ecbabf2513da899bf38273e6f2.zip | |
Implement retrieval of the default value of element and field regions.
llvm-svn: 62847
| -rw-r--r-- | clang/lib/Analysis/RegionStore.cpp | 9 | ||||
| -rw-r--r-- | clang/test/Analysis/array-struct.c | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index 2e82cc665cc..f519d4d1cd1 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/lib/Analysis/RegionStore.cpp @@ -576,6 +576,15 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) { if (state.contains<RegionKills>(R)) return UnknownVal(); + // If the region is an element of field, it may have a default value. + if (isa<ElementRegion>(R) || isa<FieldRegion>(R)) { + const MemRegion* SuperR = cast<SubRegion>(R)->getSuperRegion(); + GRStateTrait<RegionDefaultValue>::lookup_type D = + state.get<RegionDefaultValue>(SuperR); + if (D) + return *D; + } + // The location does not have a bound value. This means that it has // the value it had upon its creation and/or entry to the analyzed // function/method. These are either symbolic values or 'undefined'. diff --git a/clang/test/Analysis/array-struct.c b/clang/test/Analysis/array-struct.c index 326c2888a0b..a8de8245cd0 100644 --- a/clang/test/Analysis/array-struct.c +++ b/clang/test/Analysis/array-struct.c @@ -87,3 +87,11 @@ void f10() { char a1[4] = "abc"; char a3[6] = "abc"; } + +// Retrieve the default value of element/field region. +void f11() { + struct s a; + g(&a); + if (a.data == 0) // no-warning + a.data = 1; +} |

