overflow: update validation test
[smatch.git] / validation / context.c
blob33b70b84bdacb968cdb72dc150867ebe097b38e0
1 #define __cond_lock(c) ((c) ? ({ __context__(1); 1; }) : 0)
3 static void a(void) __attribute__((context(0,1)))
5 __context__(1);
8 static void r(void) __attribute__((context(1,0)))
10 __context__(-1);
13 extern void _ca(int fail);
14 #define ca(fail) __cond_lock(_ca(fail))
16 static void good_paired1(void)
18 a();
19 r();
22 static void good_paired2(void)
24 a();
25 r();
26 a();
27 r();
30 static void good_paired3(void)
32 a();
33 a();
34 r();
35 r();
38 static void good_lock1(void) __attribute__((context(0,1)))
40 a();
43 static void good_lock2(void) __attribute__((context(0,1)))
45 a();
46 r();
47 a();
50 static void good_lock3(void) __attribute__((context(0,1)))
52 a();
53 a();
54 r();
57 static void good_unlock1(void) __attribute__((context(1,0)))
59 r();
62 static void good_unlock2(void) __attribute__((context(1,0)))
64 a();
65 r();
66 r();
69 static void warn_lock1(void)
71 a();
74 static void warn_lock2(void)
76 a();
77 r();
78 a();
81 static void warn_lock3(void)
83 a();
84 a();
85 r();
88 static void warn_unlock1(void)
90 r();
93 static void warn_unlock2(void)
95 a();
96 r();
97 r();
100 extern int condition, condition2;
102 static int good_if1(void)
104 a();
105 if(condition) {
106 r();
107 return -1;
109 r();
110 return 0;
113 static void good_if2(void)
115 if(condition) {
116 a();
117 r();
121 static void good_if3(void)
123 a();
124 if(condition) {
125 a();
126 r();
128 r();
131 static int warn_if1(void)
133 a();
134 if(condition)
135 return -1;
136 r();
137 return 0;
140 static int warn_if2(void)
142 a();
143 if(condition) {
144 r();
145 return -1;
147 return 0;
150 static void good_while1(void)
152 a();
153 while(condition)
155 r();
158 static void good_while2(void)
160 while(condition) {
161 a();
162 r();
166 static void good_while3(void)
168 while(condition) {
169 a();
170 r();
171 if(condition2)
172 break;
173 a();
174 r();
178 static void good_while4(void)
180 a();
181 while(1) {
182 if(condition2) {
183 r();
184 break;
189 static void good_while5(void)
191 a();
192 while(1) {
193 r();
194 if(condition2)
195 break;
196 a();
200 static void warn_while1(void)
202 while(condition) {
203 a();
207 static void warn_while2(void)
209 while(condition) {
210 r();
214 static void warn_while3(void)
216 while(condition) {
217 a();
218 if(condition2)
219 break;
220 r();
224 static void good_goto1(void)
226 a();
227 goto label;
228 label:
229 r();
232 static void good_goto2(void)
234 a();
235 goto label;
236 a();
237 r();
238 label:
239 r();
242 static void good_goto3(void)
244 a();
245 if(condition)
246 goto label;
247 a();
248 r();
249 label:
250 r();
253 static void good_goto4(void)
255 if(condition)
256 goto label;
257 a();
258 r();
259 label:
263 static void good_goto5(void)
265 a();
266 if(condition)
267 goto label;
268 r();
269 return;
270 label:
271 r();
274 static void warn_goto1(void)
276 a();
277 goto label;
278 r();
279 label:
283 static void warn_goto2(void)
285 a();
286 goto label;
287 r();
288 label:
289 a();
290 r();
293 static void warn_goto3(void)
295 a();
296 if(condition)
297 goto label;
298 r();
299 label:
300 r();
303 static void good_cond_lock1(void)
305 if(ca(condition)) {
306 condition2 = 1; /* do stuff */
307 r();
311 static void warn_cond_lock1(void)
313 if(ca(condition))
314 condition2 = 1; /* do stuff */
315 r();
318 * check-name: Check -Wcontext
320 * check-error-start
321 context.c:69:13: warning: context imbalance in 'warn_lock1' - wrong count at exit
322 context.c:74:13: warning: context imbalance in 'warn_lock2' - wrong count at exit
323 context.c:81:13: warning: context imbalance in 'warn_lock3' - wrong count at exit
324 context.c:88:13: warning: context imbalance in 'warn_unlock1' - unexpected unlock
325 context.c:93:13: warning: context imbalance in 'warn_unlock2' - unexpected unlock
326 context.c:131:12: warning: context imbalance in 'warn_if1' - wrong count at exit
327 context.c:140:12: warning: context imbalance in 'warn_if2' - different lock contexts for basic block
328 context.c:202:9: warning: context imbalance in 'warn_while1' - different lock contexts for basic block
329 context.c:210:17: warning: context imbalance in 'warn_while2' - unexpected unlock
330 context.c:216:9: warning: context imbalance in 'warn_while3' - wrong count at exit
331 context.c:274:13: warning: context imbalance in 'warn_goto1' - wrong count at exit
332 context.c:283:13: warning: context imbalance in 'warn_goto2' - wrong count at exit
333 context.c:300:5: warning: context imbalance in 'warn_goto3' - different lock contexts for basic block
334 context.c:315:5: warning: context imbalance in 'warn_cond_lock1' - different lock contexts for basic block
335 * check-error-end