diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-10-13 22:55:33 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-10-13 22:55:33 +0000 |
commit | 6240cf190a660507777558660994cc566839c1a1 (patch) | |
tree | 5b728bd9651f540580a0b386af12ba3067e4dc5d | |
parent | ab28c130934eeb22f6d30661e72c39430b96b3e2 (diff) |
retain/release checker: retained objects passed to pthread_create (as
the data argument) should not be tracked further until we support full IPA.
(fixes <rdar://problem/7299394>)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84047 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/CFRefCount.cpp | 8 | ||||
-rw-r--r-- | test/Analysis/retain-release.m | 31 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 755819197e..3a4120c642 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -971,7 +971,13 @@ RetainSummary* RetainSummaryManager::getSummary(FunctionDecl* FD) { switch (strlen(FName)) { default: break; - + case 14: + if (!memcmp(FName, "pthread_create", 14)) { + // Part of: <rdar://problem/7299394>. This will be addressed + // better with IPA. + S = getPersistentStopSummary(); + } + break; case 17: // Handle: id NSMakeCollectable(CFTypeRef) diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 5f4f20d327..abda753538 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -967,6 +967,37 @@ void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint, } //===----------------------------------------------------------------------===// +// <rdar://problem/7299394> clang false positive: retained instance passed to +// thread in pthread_create marked as leak +// +// Until we have full IPA, the analyzer should stop tracking the reference +// count of objects passed to pthread_create. +// +//===----------------------------------------------------------------------===// + +struct _opaque_pthread_t {}; +struct _opaque_pthread_attr_t {}; +typedef struct _opaque_pthread_t *__darwin_pthread_t; +typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t; +typedef __darwin_pthread_t pthread_t; +typedef __darwin_pthread_attr_t pthread_attr_t; + +int pthread_create(pthread_t * restrict, const pthread_attr_t * restrict, + void *(*)(void *), void * restrict); + +void *rdar_7299394_start_routine(void *p) { + [((id) p) release]; + return 0; +} +void rdar_7299394(pthread_attr_t *attr, pthread_t *thread, void *args) { + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning + pthread_create(thread, attr, rdar_7299394_start_routine, number); +} +void rdar_7299394_positive(pthread_attr_t *attr, pthread_t *thread) { + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}} +} + +//===----------------------------------------------------------------------===// // Tests of ownership attributes. //===----------------------------------------------------------------------===// |