]> granicus.if.org Git - clang/commitdiff
retain/release checker: retained objects passed to pthread_create (as
authorTed Kremenek <kremenek@apple.com>
Tue, 13 Oct 2009 22:55:33 +0000 (22:55 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 13 Oct 2009 22:55:33 +0000 (22:55 +0000)
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

lib/Analysis/CFRefCount.cpp
test/Analysis/retain-release.m

index 755819197e7e3c9a05eb348dd5a99ff441004741..3a4120c642b1f344dca8cb6d34bd45a738606f54 100644 (file)
@@ -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)
index 5f4f20d327907f030b90531b48d68bcea8e37fde..abda7535389f826f4b9782b76b67437935555537 100644 (file)
@@ -966,6 +966,37 @@ void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint,
                               0);
 }
 
+//===----------------------------------------------------------------------===//
+// <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.
 //===----------------------------------------------------------------------===//