]> granicus.if.org Git - clang/commitdiff
Fix: <rdar://problem/7242015> [RegionStore] variable passed-by-reference (via integer...
authorTed Kremenek <kremenek@apple.com>
Tue, 22 Sep 2009 04:48:39 +0000 (04:48 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 22 Sep 2009 04:48:39 +0000 (04:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82523 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/misc-ps.m

index 81ebccb76a0a1332959351dbb8182d5c5658871a..970646f7642b771c4481b1166f83c685d1f90f05 100644 (file)
@@ -2786,6 +2786,7 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst,
         continue;
       }
 
+  tryAgain:
     if (isa<Loc>(V)) {
       if (loc::MemRegionVal* MR = dyn_cast<loc::MemRegionVal>(&V)) {
         if (Summ.getArg(idx) == DoNothingByRef)
@@ -2837,17 +2838,17 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst,
       }
       else {
         // Nuke all other arguments passed by reference.
-        // FIXME: is this necessary or correct? unbind only removes the binding.
-        // We should bind it to UnknownVal explicitly. Otherwise default value
-        // may be loaded.
+        // FIXME: is this necessary or correct? This handles the non-Region
+        //  cases.  Is it ever valid to store to these?
         state = state->unbindLoc(cast<Loc>(V));
       }
     }
-    else if (isa<nonloc::LocAsInteger>(V))
-      // FIXME: is this necessary or correct? unbind only removes the binding.
-      // We should bind it to UnknownVal explicitly. Otherwise default value
-      // may be loaded.
-      state = state->unbindLoc(cast<nonloc::LocAsInteger>(V).getLoc());
+    else if (isa<nonloc::LocAsInteger>(V)) {
+      // If we are passing a location wrapped as an integer, unwrap it and
+      // invalidate the values referred by the location.
+      V = cast<nonloc::LocAsInteger>(V).getLoc();
+      goto tryAgain;
+    }
   }
 
   // Evaluate the effect on the message receiver.
index f05ec956437253d49006a6f9679dea094f758b40..c7074d153c122812dc16cf2e541e8af51d257567 100644 (file)
@@ -632,3 +632,14 @@ double rdar_6829164_2();
   return self;
 }
 @end
+
+// <rdar://problem/7242015> - Invalidate values passed-by-reference
+// to functions when the pointer to the value is passed as an integer.
+void test_7242015_aux(unsigned long);
+int rdar_7242015() {
+  int x;
+  test_7242015_aux((unsigned long) &x); // no-warning
+  return x; // Previously we return and uninitialized value when
+            // using RegionStore.
+}
+