GNU Linux-libre 4.19.286-gnu1
[releases.git] / scripts / coccinelle / misc / orplus.cocci
1 /// Check for constants that are added but are used elsewhere as bitmasks
2 /// The results should be checked manually to ensure that the nonzero
3 /// bits in the two constants are actually disjoint.
4 ///
5 // Confidence: Moderate
6 // Copyright: (C) 2013 Julia Lawall, INRIA/LIP6.  GPLv2.
7 // Copyright: (C) 2013 Gilles Muller, INRIA/LIP6.  GPLv2.
8 // URL: http://coccinelle.lip6.fr/
9 // Comments:
10 // Options: --no-includes --include-headers
11
12 virtual org
13 virtual report
14 virtual context
15
16 @r@
17 constant c,c1;
18 identifier i,i1;
19 position p;
20 @@
21
22 (
23  c1 + c - 1
24 |
25  c1@i1 +@p c@i
26 )
27
28 @s@
29 constant r.c, r.c1;
30 identifier i;
31 expression e;
32 @@
33
34 (
35 e | c@i
36 |
37 e & c@i
38 |
39 e |= c@i
40 |
41 e &= c@i
42 |
43 e | c1@i
44 |
45 e & c1@i
46 |
47 e |= c1@i
48 |
49 e &= c1@i
50 )
51
52 @depends on s@
53 position r.p;
54 constant c1,c2;
55 @@
56
57 * c1 +@p c2
58
59 @script:python depends on s && org@
60 p << r.p;
61 @@
62
63 cocci.print_main("sum of probable bitmasks, consider |",p)
64
65 @script:python depends on s && report@
66 p << r.p;
67 @@
68
69 msg = "WARNING: sum of probable bitmasks, consider |"
70 coccilib.report.print_report(p[0],msg)