1 // RUN: %clang_analyze_cc1 -fobjc-arc -triple x86_64-darwin\
2 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
3 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP1=1 -fobjc-arc -triple x86_64-darwin\
4 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
5 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP2=1 -fobjc-arc -triple x86_64-darwin\
6 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
7 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP3=1 -fobjc-arc -triple x86_64-darwin\
8 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
9 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP4=1 -fobjc-arc -triple x86_64-darwin\
10 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
11 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP5=1 -fobjc-arc -triple x86_64-darwin\
12 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
14 #include "../Inputs/system-header-simulator-for-objc-dealloc.h"
18 void just_runloop(void) { // No warning: no statements in between
20 [[NSRunLoop mainRunLoop] run]; // no-warning
24 void just_xpcmain(void) { // No warning: no statements in between
26 xpc_main(); // no-warning
30 void runloop_init_before(void) { // Warning: object created before the loop.
32 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
34 [[NSRunLoop mainRunLoop] run];
38 void runloop_init_before_separate_pool(void) { // No warning: separate autorelease pool.
42 object = [[NSObject alloc] init]; // no-warning
45 [[NSRunLoop mainRunLoop] run];
49 void xpcmain_init_before(void) { // Warning: object created before the loop.
51 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
57 void runloop_init_before_two_objects(void) { // Warning: object created before the loop.
59 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
60 NSObject *object2 = [[NSObject alloc] init]; // no-warning, warning on the first one is enough.
63 [[NSRunLoop mainRunLoop] run];
67 void runloop_no_autoreleasepool(void) {
68 NSObject *object = [[NSObject alloc] init]; // no-warning
70 [[NSRunLoop mainRunLoop] run];
73 void runloop_init_after(void) { // No warning: objects created after the loop
75 [[NSRunLoop mainRunLoop] run];
76 NSObject *object = [[NSObject alloc] init]; // no-warning
81 void no_crash_on_empty_children(void) {
84 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
85 [[NSRunLoop mainRunLoop] run];
94 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
96 [[NSRunLoop mainRunLoop] run];
102 // expected-no-diagnostics
104 NSObject *object = [[NSObject alloc] init]; // no-warning
107 [[NSRunLoop mainRunLoop] run];
114 // expected-no-diagnostics
116 [[NSRunLoop mainRunLoop] run];
117 NSObject *object = [[NSObject alloc] init]; // no-warning
125 NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
134 @class NSConstantString;
135 #define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
136 typedef const CF_BRIDGED_TYPE(id) void * CFTypeRef;
137 typedef const struct CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef;
139 typedef enum { WARNING } Level;
140 id do_log(Level, const char *);
141 #define log(level, msg) __extension__({ (do_log(level, msg)); })
147 CFStringRef processString(const __NSConstantString *, void *);
149 #define CFSTR __builtin___CFStringMakeConstantString
154 NSString *s1 = (__bridge_transfer NSString *)processString(0, 0);
155 NSString *s2 = (__bridge_transfer NSString *)processString((CFSTR("")), ((void *)0));
156 log(WARNING, "Hello world!");
158 [[NSRunLoop mainRunLoop] run];
159 [i foo]; // no-crash // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}