diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2013-02-02 11:19:55 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2013-02-22 08:26:00 -0500 |
commit | 24f0c2d6ff859fbca45fd765f0d241528bdb4365 (patch) | |
tree | 566add45c05935086d1a01ec2c60081bbf57723e /scripts | |
parent | 5303265a48eb276b8cdee84f8e91e7f971224c5e (diff) |
scripts/coccinelle: find constant additions that could be bit ors
Semantic patch (http://coccinelle.lip6.fr/) to check for constants that are
added but are used elsewhere as bitmasks.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/misc/orplus.cocci | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/coccinelle/misc/orplus.cocci b/scripts/coccinelle/misc/orplus.cocci new file mode 100644 index 000000000000..4a28cef1484e --- /dev/null +++ b/scripts/coccinelle/misc/orplus.cocci | |||
@@ -0,0 +1,55 @@ | |||
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; | ||
18 | identifier i; | ||
19 | expression e; | ||
20 | @@ | ||
21 | |||
22 | ( | ||
23 | e | c@i | ||
24 | | | ||
25 | e & c@i | ||
26 | | | ||
27 | e |= c@i | ||
28 | | | ||
29 | e &= c@i | ||
30 | ) | ||
31 | |||
32 | @s@ | ||
33 | constant r.c,c1; | ||
34 | identifier i1; | ||
35 | position p; | ||
36 | @@ | ||
37 | |||
38 | ( | ||
39 | c1 + c - 1 | ||
40 | | | ||
41 | *c1@i1 +@p c | ||
42 | ) | ||
43 | |||
44 | @script:python depends on org@ | ||
45 | p << s.p; | ||
46 | @@ | ||
47 | |||
48 | cocci.print_main("sum of probable bitmasks, consider |",p) | ||
49 | |||
50 | @script:python depends on report@ | ||
51 | p << s.p; | ||
52 | @@ | ||
53 | |||
54 | msg = "WARNING: sum of probable bitmasks, consider |" | ||
55 | coccilib.report.print_report(p[0],msg) | ||