summaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/misc/boolinit.cocci
blob: 97ce41ce813596a98952757c68a2104a0dc7c6ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/// Bool initializations should use true and false.  Bool tests don't need
/// comparisons.  Based on contributions from Joe Perches, Rusty Russell
/// and Bruce W Allan.
///
// Confidence: High
// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.  GPLv2.
// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.  GPLv2.
// URL: http://coccinelle.lip6.fr/
// Options: -include_headers

virtual patch
virtual context
virtual org
virtual report

@depends on patch@
bool t;
symbol true;
symbol false;
@@

(
- t == true
+ t
|
- true == t
+ t
|
- t != true
+ !t
|
- true != t
+ !t
|
- t == false
+ !t
|
- false == t
+ !t
|
- t != false
+ t
|
- false != t
+ t
)

@depends on patch disable is_zero, isnt_zero@
bool t;
@@

(
- t == 1
+ t
|
- t != 1
+ !t
|
- t == 0
+ !t
|
- t != 0
+ t
)

@depends on patch@
bool b;
@@
(
 b =
- 0
+ false
|
 b =
- 1
+ true
)

// ---------------------------------------------------------------------

@r1 depends on !patch@
bool t;
position p;
@@

(
* t@p == true
|
* true == t@p
|
* t@p != true
|
* true != t@p
|
* t@p == false
|
* false == t@p
|
* t@p != false
|
* false != t@p
)

@r2 depends on !patch disable is_zero, isnt_zero@
bool t;
position p;
@@

(
* t@p == 1
|
* t@p != 1
|
* t@p == 0
|
* t@p != 0
)

@r3 depends on !patch@
bool b;
position p1,p2;
constant c;
@@
(
*b@p1 = 0
|
*b@p1 = 1
|
*b@p2 = c
)

@script:python depends on org@
p << r1.p;
@@

cocci.print_main("WARNING: Comparison to bool",p)

@script:python depends on org@
p << r2.p;
@@

cocci.print_main("WARNING: Comparison of bool to 0/1",p)

@script:python depends on org@
p1 << r3.p1;
@@

cocci.print_main("WARNING: Assignment of bool to 0/1",p1)

@script:python depends on org@
p2 << r3.p2;
@@

cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2)

@script:python depends on report@
p << r1.p;
@@

coccilib.report.print_report(p[0],"WARNING: Comparison to bool")

@script:python depends on report@
p << r2.p;
@@

coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1")

@script:python depends on report@
p1 << r3.p1;
@@

coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1")

@script:python depends on report@
p2 << r3.p2;
@@

coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant")
OpenPOWER on IntegriCloud