]> granicus.if.org Git - clang/commitdiff
Implement retrieval of the default value of element and field regions.
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 23 Jan 2009 11:22:12 +0000 (11:22 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 23 Jan 2009 11:22:12 +0000 (11:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62847 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RegionStore.cpp
test/Analysis/array-struct.c

index 2e82cc665ccd485cf4d7d91cb05f2ab7f9ed9e9d..f519d4d1cd1b17375ae4338ab9372e3f8f8672bf 100644 (file)
@@ -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'.
index 326c2888a0b99cdefe50491fca7a22f893285832..a8de8245cd0ab03ce119e6ea9cd8c84bc1ac6d62 100644 (file)
@@ -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;
+}