]> granicus.if.org Git - clang/commitdiff
[analyzer] Add a test for "release and stop tracking" behavior.
authorJordan Rose <jordan_rose@apple.com>
Mon, 20 Aug 2012 20:01:15 +0000 (20:01 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 20 Aug 2012 20:01:15 +0000 (20:01 +0000)
This is used to handle functions and methods that consume an argument
(annotated with the ns_consumed or cf_consumed attribute), but then the
argument's retain count may be further modified in a callback. We want
to warn about over-releasing, but we can't really track the object afterwards.

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

test/Analysis/retain-release.m

index ba492b7b19a7ffb8f8218da1b6e069fe70b36279..efd0532945549b485bc8987a0a913316315a521d 100644 (file)
@@ -1855,3 +1855,17 @@ id makeCollectableNonLeak() {
   [objCObject release]; // +1
   return [objCObject autorelease]; // +0
 }
+
+void consumeAndStopTracking(id NS_CONSUMED obj, void (^callback)(void));
+void testConsumeAndStopTracking() {
+  id retained = [@[] retain]; // +1
+  consumeAndStopTracking(retained, ^{}); // no-warning
+
+  id doubleRetained = [[@[] retain] retain]; // +2
+  consumeAndStopTracking(doubleRetained, ^{
+    [doubleRetained release];
+  }); // no-warning
+
+  id unretained = @[]; // +0
+  consumeAndStopTracking(unretained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
+}