annotate clang/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
2 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP1=1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
4 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
5 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP2=1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
6 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
7 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP3=1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
8 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
9 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP4=1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
10 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
11 // RUN: %clang_analyze_cc1 -DEXTRA=1 -DAP5=1 -fobjc-arc -triple x86_64-darwin\
anatofuz
parents:
diff changeset
12 // RUN: -analyzer-checker=core,osx.cocoa.RunLoopAutoreleaseLeak -verify %s
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 #include "../Inputs/system-header-simulator-for-objc-dealloc.h"
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 #ifndef EXTRA
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 void just_runloop() { // No warning: no statements in between
anatofuz
parents:
diff changeset
19 @autoreleasepool {
anatofuz
parents:
diff changeset
20 [[NSRunLoop mainRunLoop] run]; // no-warning
anatofuz
parents:
diff changeset
21 }
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 void just_xpcmain() { // No warning: no statements in between
anatofuz
parents:
diff changeset
25 @autoreleasepool {
anatofuz
parents:
diff changeset
26 xpc_main(); // no-warning
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28 }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 void runloop_init_before() { // Warning: object created before the loop.
anatofuz
parents:
diff changeset
31 @autoreleasepool {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
33 (void) object;
anatofuz
parents:
diff changeset
34 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 void runloop_init_before_separate_pool() { // No warning: separate autorelease pool.
anatofuz
parents:
diff changeset
39 @autoreleasepool {
anatofuz
parents:
diff changeset
40 NSObject *object;
anatofuz
parents:
diff changeset
41 @autoreleasepool {
anatofuz
parents:
diff changeset
42 object = [[NSObject alloc] init]; // no-warning
anatofuz
parents:
diff changeset
43 }
anatofuz
parents:
diff changeset
44 (void) object;
anatofuz
parents:
diff changeset
45 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 void xpcmain_init_before() { // Warning: object created before the loop.
anatofuz
parents:
diff changeset
50 @autoreleasepool {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
52 (void) object;
anatofuz
parents:
diff changeset
53 xpc_main();
anatofuz
parents:
diff changeset
54 }
anatofuz
parents:
diff changeset
55 }
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 void runloop_init_before_two_objects() { // Warning: object created before the loop.
anatofuz
parents:
diff changeset
58 @autoreleasepool {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
60 NSObject *object2 = [[NSObject alloc] init]; // no-warning, warning on the first one is enough.
anatofuz
parents:
diff changeset
61 (void) object;
anatofuz
parents:
diff changeset
62 (void) object2;
anatofuz
parents:
diff changeset
63 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
64 }
anatofuz
parents:
diff changeset
65 }
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 void runloop_no_autoreleasepool() {
anatofuz
parents:
diff changeset
68 NSObject *object = [[NSObject alloc] init]; // no-warning
anatofuz
parents:
diff changeset
69 (void)object;
anatofuz
parents:
diff changeset
70 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 void runloop_init_after() { // No warning: objects created after the loop
anatofuz
parents:
diff changeset
74 @autoreleasepool {
anatofuz
parents:
diff changeset
75 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
76 NSObject *object = [[NSObject alloc] init]; // no-warning
anatofuz
parents:
diff changeset
77 (void) object;
anatofuz
parents:
diff changeset
78 }
anatofuz
parents:
diff changeset
79 }
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 void no_crash_on_empty_children() {
anatofuz
parents:
diff changeset
82 @autoreleasepool {
anatofuz
parents:
diff changeset
83 for (;;) {}
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
85 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
86 (void) object;
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88 }
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 #endif
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 #ifdef AP1
anatofuz
parents:
diff changeset
93 int main() {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
95 (void) object;
anatofuz
parents:
diff changeset
96 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
97 return 0;
anatofuz
parents:
diff changeset
98 }
anatofuz
parents:
diff changeset
99 #endif
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 #ifdef AP2
anatofuz
parents:
diff changeset
102 // expected-no-diagnostics
anatofuz
parents:
diff changeset
103 int main() {
anatofuz
parents:
diff changeset
104 NSObject *object = [[NSObject alloc] init]; // no-warning
anatofuz
parents:
diff changeset
105 (void) object;
anatofuz
parents:
diff changeset
106 @autoreleasepool {
anatofuz
parents:
diff changeset
107 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109 return 0;
anatofuz
parents:
diff changeset
110 }
anatofuz
parents:
diff changeset
111 #endif
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 #ifdef AP3
anatofuz
parents:
diff changeset
114 // expected-no-diagnostics
anatofuz
parents:
diff changeset
115 int main() {
anatofuz
parents:
diff changeset
116 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
117 NSObject *object = [[NSObject alloc] init]; // no-warning
anatofuz
parents:
diff changeset
118 (void) object;
anatofuz
parents:
diff changeset
119 return 0;
anatofuz
parents:
diff changeset
120 }
anatofuz
parents:
diff changeset
121 #endif
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123 #ifdef AP4
anatofuz
parents:
diff changeset
124 int main() {
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
126 (void) object;
anatofuz
parents:
diff changeset
127 xpc_main();
anatofuz
parents:
diff changeset
128 return 0;
anatofuz
parents:
diff changeset
129 }
anatofuz
parents:
diff changeset
130 #endif
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 #ifdef AP5
anatofuz
parents:
diff changeset
133 @class NSString;
anatofuz
parents:
diff changeset
134 @class NSConstantString;
anatofuz
parents:
diff changeset
135 #define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
anatofuz
parents:
diff changeset
136 typedef const CF_BRIDGED_TYPE(id) void * CFTypeRef;
anatofuz
parents:
diff changeset
137 typedef const struct CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef;
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 typedef enum { WARNING } Level;
anatofuz
parents:
diff changeset
140 id do_log(Level, const char *);
anatofuz
parents:
diff changeset
141 #define log(level, msg) __extension__({ (do_log(level, msg)); })
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 @interface I
anatofuz
parents:
diff changeset
144 - foo;
anatofuz
parents:
diff changeset
145 @end
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 CFStringRef processString(const __NSConstantString *, void *);
anatofuz
parents:
diff changeset
148
anatofuz
parents:
diff changeset
149 #define CFSTR __builtin___CFStringMakeConstantString
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 int main() {
anatofuz
parents:
diff changeset
152 I *i;
anatofuz
parents:
diff changeset
153 @autoreleasepool {
anatofuz
parents:
diff changeset
154 NSString *s1 = (__bridge_transfer NSString *)processString(0, 0);
anatofuz
parents:
diff changeset
155 NSString *s2 = (__bridge_transfer NSString *)processString((CFSTR("")), ((void *)0));
anatofuz
parents:
diff changeset
156 log(WARNING, "Hello world!");
anatofuz
parents:
diff changeset
157 }
anatofuz
parents:
diff changeset
158 [[NSRunLoop mainRunLoop] run];
anatofuz
parents:
diff changeset
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}}
anatofuz
parents:
diff changeset
160 }
anatofuz
parents:
diff changeset
161 #endif