diff options
author | Devin Coughlin <dcoughlin@apple.com> | 2017-11-25 14:57:42 +0000 |
---|---|---|
committer | Devin Coughlin <dcoughlin@apple.com> | 2017-11-25 14:57:42 +0000 |
commit | cc5915a5e15d098952605556b2b7a75632fb41e3 (patch) | |
tree | f05a5ff589a30db450500626fc9f27b41201ad0b /clang/test | |
parent | 67e60434c30e9a53cf8c994a4c97a689732cfc8f (diff) | |
download | bcm5719-llvm-cc5915a5e15d098952605556b2b7a75632fb41e3.tar.gz bcm5719-llvm-cc5915a5e15d098952605556b2b7a75632fb41e3.zip |
[analyzer] Teach RetainCountChecker about CoreMedia APIs
Teach the retain-count checker that CoreMedia reference types use
CoreFoundation-style reference counting. This enables the checker
to catch leaks and over releases of those types.
rdar://problem/33599757
llvm-svn: 318979
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/retain-release.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/test/Analysis/retain-release.m b/clang/test/Analysis/retain-release.m index a1cc62cb359..4add50eb5d0 100644 --- a/clang/test/Analysis/retain-release.m +++ b/clang/test/Analysis/retain-release.m @@ -450,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. |