]> granicus.if.org Git - clang/commitdiff
Fix lookup of fields from lazy bindings to check if the region is
authorTed Kremenek <kremenek@apple.com>
Tue, 9 Feb 2010 19:11:53 +0000 (19:11 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 9 Feb 2010 19:11:53 +0000 (19:11 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95679 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/RegionStore.cpp
test/Analysis/misc-ps.m

index c08be0cff62012d7ea4161aea61473f86a2fd033..a6646436d5ee6439c64e825db1633c2903eb2d8e 100644 (file)
@@ -1054,7 +1054,7 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) {
     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 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) {
     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 @@ SVal RegionStoreManager::RetrieveFieldOrElementCommon(Store store,
   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));
   }
index 20eed9cb3de09a68d4d47418d23e2f1cff5919d6..fa05f6f6030885fb12364bf7a0195793cf0e1388 100644 (file)
@@ -915,3 +915,21 @@ void rdar7582031_test_static_init_zero_b() {
   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
+}