forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/scripts/coccinelle/misc/boolinit.cocci
....@@ -1,10 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /// Bool initializations should use true and false. Bool tests don't need
23 /// comparisons. Based on contributions from Joe Perches, Rusty Russell
34 /// and Bruce W Allan.
45 ///
56 // Confidence: High
6
-// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
7
-// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7
+// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
8
+// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
89 // URL: http://coccinelle.lip6.fr/
910 // Options: --include-headers
1011
....@@ -13,10 +14,17 @@
1314 virtual org
1415 virtual report
1516
17
+@boolok@
18
+symbol true,false;
19
+@@
20
+(
21
+true
22
+|
23
+false
24
+)
25
+
1626 @depends on patch@
1727 bool t;
18
-symbol true;
19
-symbol false;
2028 @@
2129
2230 (
....@@ -63,7 +71,7 @@
6371 + t
6472 )
6573
66
-@depends on patch@
74
+@depends on patch && boolok@
6775 bool b;
6876 @@
6977 (
....@@ -116,15 +124,24 @@
116124 * t@p != 0
117125 )
118126
119
-@r3 depends on !patch@
127
+@r3 depends on !patch && boolok@
120128 bool b;
121
-position p1,p2;
122
-constant c;
129
+position p1;
123130 @@
124131 (
125132 *b@p1 = 0
126133 |
127134 *b@p1 = 1
135
+)
136
+
137
+@r4 depends on !patch@
138
+bool b;
139
+position p2;
140
+identifier i;
141
+constant c != {0,1};
142
+@@
143
+(
144
+ b = i
128145 |
129146 *b@p2 = c
130147 )
....@@ -139,19 +156,19 @@
139156 p << r2.p;
140157 @@
141158
142
-cocci.print_main("WARNING: Comparison of bool to 0/1",p)
159
+cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)
143160
144161 @script:python depends on org@
145162 p1 << r3.p1;
146163 @@
147164
148
-cocci.print_main("WARNING: Assignment of bool to 0/1",p1)
165
+cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)
149166
150167 @script:python depends on org@
151
-p2 << r3.p2;
168
+p2 << r4.p2;
152169 @@
153170
154
-cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2)
171
+cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)
155172
156173 @script:python depends on report@
157174 p << r1.p;
....@@ -163,16 +180,16 @@
163180 p << r2.p;
164181 @@
165182
166
-coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1")
183
+coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")
167184
168185 @script:python depends on report@
169186 p1 << r3.p1;
170187 @@
171188
172
-coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1")
189
+coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")
173190
174191 @script:python depends on report@
175
-p2 << r3.p2;
192
+p2 << r4.p2;
176193 @@
177194
178
-coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant")
195
+coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")