]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / test / Analysis / Checkers / RunLoopAutoreleaseLeakChecker.m
1 // UNSUPPORTED: system-windows
2 // RUN: %clang_analyze_cc1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
3 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP1=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
4 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP2=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
5 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP3=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
6 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP4=1 -fobjc-arc -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak %s -triple x86_64-darwin -verify
7
8 #include "../Inputs/system-header-simulator-for-objc-dealloc.h"
9
10 #ifndef EXTRA
11
12 void just_runloop() { // No warning: no statements in between
13   @autoreleasepool {
14     [[NSRunLoop mainRunLoop] run]; // no-warning
15   }
16 }
17
18 void just_xpcmain() { // No warning: no statements in between
19   @autoreleasepool {
20     xpc_main(); // no-warning
21   }
22 }
23
24 void runloop_init_before() { // Warning: object created before the loop.
25   @autoreleasepool {
26     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}}
27     (void) object;
28     [[NSRunLoop mainRunLoop] run]; 
29   }
30 }
31
32 void xpcmain_init_before() { // Warning: object created before the loop.
33   @autoreleasepool {
34     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}}
35     (void) object;
36     xpc_main(); 
37   }
38 }
39
40 void runloop_init_before_two_objects() { // Warning: object created before the loop.
41   @autoreleasepool {
42     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}}
43     NSObject *object2 = [[NSObject alloc] init]; // no-warning, warning on the first one is enough.
44     (void) object;
45     (void) object2;
46     [[NSRunLoop mainRunLoop] run]; 
47   }
48 }
49
50 void runloop_no_autoreleasepool() {
51   NSObject *object = [[NSObject alloc] init]; // no-warning
52   (void)object;
53   [[NSRunLoop mainRunLoop] run];
54 }
55
56 void runloop_init_after() { // No warning: objects created after the loop
57   @autoreleasepool {
58     [[NSRunLoop mainRunLoop] run]; 
59     NSObject *object = [[NSObject alloc] init]; // no-warning
60     (void) object;
61   }
62 }
63
64 #endif
65
66 #ifdef AP1
67 int main() {
68     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}}
69     (void) object;
70     [[NSRunLoop mainRunLoop] run]; 
71     return 0;
72 }
73 #endif
74
75 #ifdef AP2
76 // expected-no-diagnostics
77 int main() {
78   NSObject *object = [[NSObject alloc] init]; // no-warning
79   (void) object;
80   @autoreleasepool {
81     [[NSRunLoop mainRunLoop] run]; 
82   }
83   return 0;
84 }
85 #endif
86
87 #ifdef AP3
88 // expected-no-diagnostics
89 int main() {
90     [[NSRunLoop mainRunLoop] run];
91     NSObject *object = [[NSObject alloc] init]; // no-warning
92     (void) object;
93     return 0;
94 }
95 #endif
96
97 #ifdef AP4
98 int main() {
99     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}}
100     (void) object;
101     xpc_main();
102     return 0;
103 }
104 #endif