Linux-libre 5.0.10-gnu
[librecmc/linux-libre.git] / scripts / coccinelle / misc / boolreturn.cocci
1 // SPDX-License-Identifier: GPL-2.0
2 /// Return statements in functions returning bool should use
3 /// true/false instead of 1/0.
4 //
5 // Confidence: High
6 // Options: --no-includes --include-headers
7
8 virtual patch
9 virtual report
10 virtual context
11
12 @r1 depends on patch@
13 identifier fn;
14 typedef bool;
15 symbol false;
16 symbol true;
17 @@
18
19 bool fn ( ... )
20 {
21 <...
22 return
23 (
24 - 0
25 + false
26 |
27 - 1
28 + true
29 )
30   ;
31 ...>
32 }
33
34 @r2 depends on report || context@
35 identifier fn;
36 position p;
37 @@
38
39 bool fn ( ... )
40 {
41 <...
42 return
43 (
44 * 0@p
45 |
46 * 1@p
47 )
48   ;
49 ...>
50 }
51
52
53 @script:python depends on report@
54 p << r2.p;
55 fn << r2.fn;
56 @@
57
58 msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn
59 coccilib.report.print_report(p[0], msg)