[cfe-commits] r62847 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/array-struct.c

Zhongxing Xu xuzhongxing at gmail.com
Fri Jan 23 03:22:20 PST 2009


Author: zhongxingxu
Date: Fri Jan 23 05:22:12 2009
New Revision: 62847

URL: http://llvm.org/viewvc/llvm-project?rev=62847&view=rev
Log:
Implement retrieval of the default value of element and field regions.

Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp
    cfe/trunk/test/Analysis/array-struct.c

Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=62847&r1=62846&r2=62847&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Fri Jan 23 05:22:12 2009
@@ -576,6 +576,15 @@
   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'.

Modified: cfe/trunk/test/Analysis/array-struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/array-struct.c?rev=62847&r1=62846&r2=62847&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/array-struct.c (original)
+++ cfe/trunk/test/Analysis/array-struct.c Fri Jan 23 05:22:12 2009
@@ -87,3 +87,11 @@
   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;
+}





More information about the cfe-commits mailing list