Move the implications checking to after the scripts have set their states.
[smatch.git] / validation / context-named.c
blob58310e9fe53a8f4d54b2ba6144d0639d005382d7
1 static void a(void) __attribute__((context(TEST,0,1)))
3 __context__(TEST,1);
6 static void r(void) __attribute__((context(TEST,1,0)))
8 __context__(TEST,-1,1);
11 static void a2(void) __attribute__((context(TEST2,0,1)))
13 __context__(TEST2,1);
16 static void r2(void) __attribute__((context(TEST2,1,0)))
18 __context__(TEST2,-1,1);
21 #define check_test2() __context__(TEST2,0,1)
23 static void good_paired1(void)
25 a();
26 a2();
27 r();
28 r2();
31 static void good_paired2(void)
33 a();
34 r();
35 a();
36 r();
37 a2();
38 r2();
41 static void good_paired3(void)
43 a();
44 a();
45 r();
46 r();
47 a2();
48 a2();
49 r2();
50 r2();
53 static void good_lock1(void) __attribute__((context(TEST,0,1)))
55 a();
58 static void good_lock2(void) __attribute__((context(TEST,0,1)))
60 a();
61 r();
62 a();
65 static void good_lock3(void) __attribute__((context(TEST,0,1)))
67 a();
68 a();
69 r();
72 static void good_unlock1(void) __attribute__((context(TEST,1,0)))
74 r();
77 static void good_unlock2(void) __attribute__((context(TEST,1,0)))
79 a();
80 r();
81 r();
84 static void warn_lock1(void)
86 a();
89 static void warn_lock2(void)
91 a();
92 r();
93 a();
96 static void warn_lock3(void)
98 a();
99 a();
100 r();
103 static void warn_unlock1(void)
105 r();
108 static void warn_unlock2(void)
110 a();
111 r();
112 r();
115 extern int condition, condition2;
117 static int good_if1(void)
119 a();
120 if(condition) {
121 r();
122 return -1;
124 r();
125 return 0;
128 static void good_if2(void)
130 if(condition) {
131 a();
132 r();
136 static void good_if3(void)
138 a();
139 if(condition) {
140 a();
141 r();
143 r();
146 static int warn_if1(void)
148 a();
149 if(condition)
150 return -1;
151 r();
152 return 0;
155 static int warn_if2(void)
157 a();
158 if(condition) {
159 r();
160 return -1;
162 return 0;
165 static void good_while1(void)
167 a();
168 while(condition)
170 r();
173 static void good_while2(void)
175 while(condition) {
176 a();
177 r();
181 static void good_while3(void)
183 while(condition) {
184 a();
185 r();
186 if(condition2)
187 break;
188 a();
189 r();
193 static void good_while4(void)
195 a();
196 while(1) {
197 if(condition2) {
198 r();
199 break;
204 static void good_while5(void)
206 a();
207 while(1) {
208 r();
209 if(condition2)
210 break;
211 a();
215 static void warn_while1(void)
217 while(condition) {
218 a();
222 static void warn_while2(void)
224 while(condition) {
225 r();
229 static void warn_while3(void)
231 while(condition) {
232 a();
233 if(condition2)
234 break;
235 r();
239 static void good_goto1(void)
241 a();
242 goto label;
243 label:
244 r();
247 static void good_goto2(void)
249 a();
250 goto label;
251 a();
252 r();
253 label:
254 r();
257 static void good_goto3(void)
259 a();
260 if(condition)
261 goto label;
262 a();
263 r();
264 label:
265 r();
268 static void good_goto4(void)
270 if(condition)
271 goto label;
272 a();
273 r();
274 label:
278 static void good_goto5(void)
280 a();
281 if(condition)
282 goto label;
283 r();
284 return;
285 label:
286 r();
289 static void warn_goto1(void)
291 a();
292 goto label;
293 r();
294 label:
298 static void warn_goto2(void)
300 a();
301 goto label;
302 r();
303 label:
304 a();
305 r();
308 static void warn_goto3(void)
310 a();
311 if(condition)
312 goto label;
313 r();
314 label:
315 r();
318 static void warn_multiple1(void)
320 a();
321 a2();
324 static void warn_multiple2(void)
326 a2();
327 a();
330 static void warn_mixed1(void)
332 a2();
333 r();
336 static void warn_mixed2(void)
338 a2();
339 if (condition) {
340 a();
341 r2();
343 r();
346 static void warn_mixed3(void)
348 a2();
349 if (condition) {
350 r2();
351 return;
353 r();
356 static void warn_mixed4(void)
358 a2();
359 if (condition) {
360 a();
361 r();
362 return;
364 r();
367 static void good_mixed1(void)
369 if (condition) {
370 a();
371 r();
372 } else {
373 a2();
374 r2();
378 static void good_mixed2(void)
380 if (condition) {
381 a();
382 r();
384 a2();
385 r2();
388 static int need_lock(void) __attribute__((context(TEST,1,1)))
392 static void need_lock_exact(void) __attribute__((exact_context(TEST,1,1)))
396 static void need_lock2(void) __attribute__((context(TEST,1,1)))
398 need_lock();
401 static void good_fn(void)
403 a();
404 need_lock();
405 r();
408 static void good_fn2(void)
410 a();
411 a();
412 need_lock();
413 r();
414 r();
417 static void good_fn2(void)
419 a();
420 if (condition)
421 need_lock();
422 r();
425 static void good_fn3(void) __attribute__((context(TEST,1,1)))
427 if (condition)
428 need_lock2();
431 static void warn_fn(void)
433 a2();
434 need_lock();
435 r2();
438 static void warn_fn2(void)
440 a2();
441 need_lock2();
442 r2();
445 static void good_exact_fn(void)
447 a();
448 need_lock_exact();
449 r();
452 static void warn_exact_fn1(void)
454 a();
455 a();
456 need_lock_exact();
457 r();
458 r();
461 static void warn_exact_fn2(void)
463 a2();
464 need_lock_exact();
465 r2();
468 static inline void need_lock3(void) __attribute__((context(TEST,1,1)))
472 static void warn_fn3(void)
474 a2();
475 need_lock3();
476 r2();
479 #define __acquire(x) __context__(x,1)
480 #define __release(x) __context__(x,-1)
482 #define rl() \
483 do { __acquire(RCU); } while (0)
485 #define ru() \
486 do { __release(RCU); } while (0)
488 static void good_mixed_with_if(void)
490 rl();
492 if (condition) {
493 a();
494 r();
497 ru();
501 * check-name: Check -Wcontext with lock names
503 * check-error-start
504 context-named.c:86:3: warning: context imbalance in 'warn_lock1': wrong count at exit
505 context-named.c:86:3: context 'TEST': wanted 0, got 1
506 context-named.c:93:3: warning: context imbalance in 'warn_lock2': wrong count at exit
507 context-named.c:93:3: context 'TEST': wanted 0, got 1
508 context-named.c:100:3: warning: context imbalance in 'warn_lock3': wrong count at exit
509 context-named.c:100:3: context 'TEST': wanted 0, got 1
510 context-named.c:105:3: warning: context problem in 'warn_unlock1': 'r' expected different context
511 context-named.c:105:3: context 'TEST': wanted >= 1, got 0
512 context-named.c:112:3: warning: context problem in 'warn_unlock2': 'r' expected different context
513 context-named.c:112:3: context 'TEST': wanted >= 1, got 0
514 context-named.c:152:9: warning: context imbalance in 'warn_if1': wrong count at exit
515 context-named.c:152:9: context 'TEST': wanted 0, got 1
516 context-named.c:162:9: warning: context imbalance in 'warn_if2': wrong count at exit
517 context-named.c:162:9: context 'TEST': wanted 0, got 1
518 context-named.c:218:4: warning: context imbalance in 'warn_while1': wrong count at exit
519 context-named.c:218:4: context 'TEST': wanted 0, got 1
520 context-named.c:225:4: warning: context problem in 'warn_while2': 'r' expected different context
521 context-named.c:225:4: context 'TEST': wanted >= 1, got 0
522 context-named.c:235:4: warning: context imbalance in 'warn_while3': wrong count at exit
523 context-named.c:235:4: context 'TEST': wanted 0, got 1
524 context-named.c:295:5: warning: context imbalance in 'warn_goto1': wrong count at exit
525 context-named.c:295:5: context 'TEST': wanted 0, got 1
526 context-named.c:305:6: warning: context imbalance in 'warn_goto2': wrong count at exit
527 context-named.c:305:6: context 'TEST': wanted 0, got 1
528 context-named.c:315:6: warning: context problem in 'warn_goto3': 'r' expected different context
529 context-named.c:315:6: context 'TEST': wanted >= 1, got 0
530 context-named.c:321:7: warning: context imbalance in 'warn_multiple1': wrong count at exit
531 context-named.c:321:7: context 'TEST': wanted 0, got 1
532 context-named.c:327:6: warning: context imbalance in 'warn_multiple2': wrong count at exit
533 context-named.c:327:6: context 'TEST2': wanted 0, got 1
534 context-named.c:333:6: warning: context problem in 'warn_mixed1': 'r' expected different context
535 context-named.c:333:6: context 'TEST': wanted >= 1, got 0
536 context-named.c:343:6: warning: context problem in 'warn_mixed2': 'r' expected different context
537 context-named.c:343:6: context 'TEST': wanted >= 1, got 0
538 context-named.c:353:6: warning: context problem in 'warn_mixed3': 'r' expected different context
539 context-named.c:353:6: context 'TEST': wanted >= 1, got 0
540 context-named.c:364:6: warning: context imbalance in 'warn_mixed4': wrong count at exit
541 context-named.c:364:6: context 'TEST2': wanted 0, got 1
542 context-named.c:434:14: warning: context problem in 'warn_fn': 'need_lock' expected different context
543 context-named.c:434:14: context 'TEST': wanted >= 1, got 0
544 context-named.c:441:15: warning: context problem in 'warn_fn2': 'need_lock2' expected different context
545 context-named.c:441:15: context 'TEST': wanted >= 1, got 0
546 context-named.c:456:20: warning: context problem in 'warn_exact_fn1': 'need_lock_exact' expected different context
547 context-named.c:456:20: context 'TEST': wanted 1, got 2
548 context-named.c:464:20: warning: context problem in 'warn_exact_fn2': 'need_lock_exact' expected different context
549 context-named.c:464:20: context 'TEST': wanted 1, got 0
550 context-named.c:475:15: warning: context problem in 'warn_fn3': 'need_lock3' expected different context
551 context-named.c:475:15: context 'TEST': wanted >= 1, got 0
552 * check-error-end