]> granicus.if.org Git - clang/commitdiff
Add more retain-checker tests for GC mode when using NSMakeCollectable.
authorTed Kremenek <kremenek@apple.com>
Wed, 3 Jun 2009 19:19:06 +0000 (19:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 3 Jun 2009 19:19:06 +0000 (19:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72799 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/retain-release-gc-only.m

index 70ad54f8aa4a82ecd7327b81cd69b5a905d84847..cc4a40db092fbf5b74de566d3466db588b03d721 100644 (file)
@@ -101,6 +101,11 @@ extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn stat
 
 CFTypeRef CFMakeCollectable(CFTypeRef cf) ;
 
+static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef 
+cf) {
+    return cf ? (id)CFMakeCollectable(cf) : ((void*)0);
+}
+
 //===----------------------------------------------------------------------===//
 // Test cases.
 //===----------------------------------------------------------------------===//
@@ -124,6 +129,31 @@ void f3() {
   CFRetain(A);
 }
 
+void f3b() {
+  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
+  CFMakeCollectable(A);
+}
+
+
+void f4() {
+  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}}
+  NSMakeCollectable(A);
+  CFRetain(A);
+}
+
+void f4b() {
+  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
+  NSMakeCollectable(A);
+}
+
+void f5() {
+  id x = [NSMakeCollectable(CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks)) autorelease]; // no-warning
+}
+
+void f5b() {
+  id x = [(id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks) autorelease]; // expected-warning{{leak}}
+}
+
 // Test return of non-owned objects in contexts where an owned object
 // is expected.
 @interface TestReturnNotOwnedWhenExpectedOwned
@@ -133,7 +163,7 @@ void f3() {
 
 @implementation TestReturnNotOwnedWhenExpectedOwned
 - (NSString*)newString {
-  NSString *s = [NSString stringWithUTF8String:"hello"]; // expected-warning{{Potential leak (when using garbage collection) of an object allocated on line 136 and stored into 's'}}
+  NSString *s = [NSString stringWithUTF8String:"hello"]; // expected-warning{{Potential leak (when using garbage collection) of an object allocated}}
   CFRetain(s);
   return s;
 }