From: Ted Kremenek Date: Tue, 13 Oct 2009 22:55:33 +0000 (+0000) Subject: retain/release checker: retained objects passed to pthread_create (as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6240cf190a660507777558660994cc566839c1a1;p=clang retain/release checker: retained objects passed to pthread_create (as the data argument) should not be tracked further until we support full IPA. (fixes ) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84047 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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: . 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 @@ -966,6 +966,37 @@ void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint, 0); } +//===----------------------------------------------------------------------===// +// 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. //===----------------------------------------------------------------------===//