Add some functions to handle tracker lists.
[smatch.git] / validation / context.c
blob0b45ba3a15f1c140b6cc4a72ef9ea8ccd41703ef
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 static void warn_odd_looping(void)
320 int i;
322 for (i = 0; i < 2; i++)
323 a();
324 for (i = 0; i < 2; i++)
325 r();
328 static void warn_huge_switch(void)
330 a();
332 switch(condition) {
333 case 1:
334 r();
335 break;
336 case 2:
337 r();
338 break;
339 case 3:
340 r();
341 break;
342 case 4:
343 r();
344 break;
345 case 5:
346 r();
347 break;
348 case 11:
349 r();
350 break;
351 case 12:
352 r();
353 break;
354 case 13:
355 r();
356 break;
357 case 14:
358 r();
359 case 15:
360 r();
361 break;
362 case 16:
363 r();
364 break;
365 case 17:
366 r();
367 break;
371 static int warn_conditional(void)
373 if (condition)
374 return 0;
376 a();
377 if (condition == 0)
378 return 1;
379 r();
380 return 0;
384 * check-name: Check -Wcontext
386 * check-error-start
387 context.c:71:3: warning: context imbalance in 'warn_lock1': wrong count at exit
388 context.c:71:3: default context: wanted 0, got 1
389 context.c:78:3: warning: context imbalance in 'warn_lock2': wrong count at exit
390 context.c:78:3: default context: wanted 0, got 1
391 context.c:85:3: warning: context imbalance in 'warn_lock3': wrong count at exit
392 context.c:85:3: default context: wanted 0, got 1
393 context.c:90:3: warning: context problem in 'warn_unlock1': 'r' expected different context
394 context.c:90:3: default context: wanted >= 1, got 0
395 context.c:97:3: warning: context problem in 'warn_unlock2': 'r' expected different context
396 context.c:97:3: default context: wanted >= 1, got 0
397 context.c:137:9: warning: context imbalance in 'warn_if1': wrong count at exit
398 context.c:137:9: default context: wanted 0, got 1
399 context.c:147:9: warning: context imbalance in 'warn_if2': wrong count at exit
400 context.c:147:9: default context: wanted 0, got 1
401 context.c:203:4: warning: context imbalance in 'warn_while1': wrong count at exit
402 context.c:203:4: default context: wanted 0, got 1
403 context.c:210:4: warning: context problem in 'warn_while2': 'r' expected different context
404 context.c:210:4: default context: wanted >= 1, got 0
405 context.c:220:4: warning: context imbalance in 'warn_while3': wrong count at exit
406 context.c:220:4: default context: wanted 0, got 1
407 context.c:280:5: warning: context imbalance in 'warn_goto1': wrong count at exit
408 context.c:280:5: default context: wanted 0, got 1
409 context.c:290:6: warning: context imbalance in 'warn_goto2': wrong count at exit
410 context.c:290:6: default context: wanted 0, got 1
411 context.c:300:6: warning: context problem in 'warn_goto3': 'r' expected different context
412 context.c:300:6: default context: wanted >= 1, got 0
413 context.c:315:6: warning: context problem in 'warn_cond_lock1': 'r' expected different context
414 context.c:315:6: default context: wanted >= 1, got 0
415 context.c:325:10: warning: context problem in 'warn_odd_looping': 'r' expected different context
416 context.c:325:10: default context: wanted >= 1, got 0
417 context.c:360:10: warning: context problem in 'warn_huge_switch': 'r' expected different context
418 context.c:360:10: default context: wanted >= 1, got 0
419 context.c:380:12: warning: context imbalance in 'warn_conditional': wrong count at exit
420 context.c:380:12: default context: wanted 0, got 1
421 * check-error-end