[cfe-commits] r95679 - in /cfe/trunk: lib/Checker/RegionStore.cpp test/Analysis/misc-ps.m

Ted Kremenek kremenek at apple.com
Tue Feb 9 11:11:53 PST 2010


Author: kremenek
Date: Tue Feb  9 13:11:53 2010
New Revision: 95679

URL: http://llvm.org/viewvc/llvm-project?rev=95679&view=rev
Log:
Fix lookup of fields from lazy bindings to check if the region is
NULL, not the store, to determine if a lookup succeeded.  The store
can be null if it contained no bindings.  This fixes a false positive
reported to me by a user of the analyzer.

Modified:
    cfe/trunk/lib/Checker/RegionStore.cpp
    cfe/trunk/test/Analysis/misc-ps.m

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

==============================================================================
--- cfe/trunk/lib/Checker/RegionStore.cpp (original)
+++ cfe/trunk/lib/Checker/RegionStore.cpp Tue Feb  9 13:11:53 2010
@@ -1054,7 +1054,7 @@
     const std::pair<Store, const MemRegion *> &X =
       GetLazyBinding(B, ER->getSuperRegion());
 
-    if (X.first)
+    if (X.second)
       return std::make_pair(X.first,
                             MRMgr.getElementRegionWithSuper(ER, X.second));
   }
@@ -1062,7 +1062,7 @@
     const std::pair<Store, const MemRegion *> &X =
       GetLazyBinding(B, FR->getSuperRegion());
 
-    if (X.first)
+    if (X.second)
       return std::make_pair(X.first,
                             MRMgr.getFieldRegionWithSuper(FR, X.second));
   }
@@ -1179,13 +1179,9 @@
   const MemRegion *lazyBindingRegion = NULL;
   llvm::tie(lazyBindingStore, lazyBindingRegion) = GetLazyBinding(B, R);
 
-  if (lazyBindingStore) {
-    assert(lazyBindingRegion && "Lazy-binding region not set");
-
-    if (isa<ElementRegion>(R))
-      return RetrieveElement(lazyBindingStore,
-                             cast<ElementRegion>(lazyBindingRegion));
-
+  if (lazyBindingRegion) {
+    if (const ElementRegion *ER = dyn_cast<ElementRegion>(lazyBindingRegion))
+      return RetrieveElement(lazyBindingStore, ER);
     return RetrieveField(lazyBindingStore,
                          cast<FieldRegion>(lazyBindingRegion));
   }

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=95679&r1=95678&r2=95679&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Tue Feb  9 13:11:53 2010
@@ -915,3 +915,21 @@
   int *p = 0;
   *p = 0xDEADBEEF;
 }
+
+//===----------------------------------------------------------------------===//
+// Test handling of parameters that are structs that contain floats and       //
+// nested fields.                                                             //
+//===----------------------------------------------------------------------===//
+
+struct s_rev95547_nested { float x, y; };
+struct s_rev95547 {
+  struct s_rev95547_nested z1;
+  struct s_rev95547_nested z2;
+};
+float foo_rev95547(struct s_rev95547 w) {
+  return w.z1.x + 20.0; // no-warning
+}
+void foo_rev95547_b(struct s_rev95547 w) {
+  struct s_rev95547 w2 = w;
+  w2.z1.x += 20.0; // no-warning
+}





More information about the cfe-commits mailing list