summaryrefslogtreecommitdiff
path: root/test/Analysis/retain-release.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/retain-release.m')
-rw-r--r--test/Analysis/retain-release.m62
1 files changed, 59 insertions, 3 deletions
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index 29af194a3d67..4add50eb5d0d 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -325,6 +325,9 @@ typedef const struct __CFUUID * CFUUIDRef;
extern
void *CFPlugInInstanceCreate(CFAllocatorRef allocator, CFUUIDRef factoryUUID, CFUUIDRef typeUUID);
+typedef struct {
+ int ref;
+} isl_basic_map;
//===----------------------------------------------------------------------===//
// Test cases.
@@ -447,6 +450,51 @@ void f10(io_service_t media, DADiskRef d, CFStringRef s) {
if (session) NSLog(@"ok");
}
+
+// Handle CoreMedia API
+
+struct CMFoo;
+typedef struct CMFoo *CMFooRef;
+
+CMFooRef CMCreateFooRef();
+CMFooRef CMGetFooRef();
+
+typedef signed long SInt32;
+typedef SInt32 OSStatus;
+OSStatus CMCreateFooAndReturnViaOutParameter(CMFooRef * CF_RETURNS_RETAINED fooOut);
+
+void testLeakCoreMediaReferenceType() {
+ CMFooRef f = CMCreateFooRef(); // expected-warning{{leak}}
+}
+
+void testOverReleaseMediaReferenceType() {
+ CMFooRef f = CMGetFooRef();
+ CFRelease(f); // expected-warning{{Incorrect decrement of the reference count}}
+}
+
+void testOkToReleaseReturnsRetainedOutParameter() {
+ CMFooRef foo = 0;
+ OSStatus status = CMCreateFooAndReturnViaOutParameter(&foo);
+
+ if (status != 0)
+ return;
+
+ CFRelease(foo); // no-warning
+}
+
+void testLeakWithReturnsRetainedOutParameter() {
+ CMFooRef foo = 0;
+ OSStatus status = CMCreateFooAndReturnViaOutParameter(&foo);
+
+ if (status != 0)
+ return;
+
+ // FIXME: Ideally we would report a leak here since it is the caller's
+ // responsibility to release 'foo'. However, we don't currently have
+ // a mechanism in this checker to only require a release when a successful
+ // status is returned.
+}
+
// Test retain/release checker with CFString and CFMutableArray.
void f11() {
// Create the array.
@@ -574,6 +622,14 @@ void f17(int x, CFTypeRef p) {
}
}
+__attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_cow(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap);
+
+// Test custom diagnostics for generalized objects.
+void f18(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
+ // After this call, 'bmap' has a +1 reference count.
+ bmap = isl_basic_map_cow(bmap); // expected-warning {{Potential leak of an object}}
+}
+
// Test basic tracking of ivars associated with 'self'. For the retain/release
// checker we currently do not want to flag leaks associated with stores
// of tracked objects to ivars.
@@ -1776,15 +1832,15 @@ CFArrayRef camel_copymachine() {
// rdar://problem/8024350
@protocol F18P
-- (id) clone;
+- (id) clone; // expected-note 2 {{method declared here}}
@end
@interface F18 : NSObject<F18P> @end
@interface F18(Cat)
-- (id) clone NS_RETURNS_RETAINED;
+- (id) clone NS_RETURNS_RETAINED; // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
@end
@implementation F18
-- (id) clone {
+- (id) clone { // expected-warning {{overriding method has mismatched ns_returns_retained attributes}}
return [F18 alloc];
}
@end