Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Check for constants that are added but are used elsewhere as bitmasks
0003 /// The results should be checked manually to ensure that the nonzero
0004 /// bits in the two constants are actually disjoint.
0005 ///
0006 // Confidence: Moderate
0007 // Copyright: (C) 2013 Julia Lawall, INRIA/LIP6.
0008 // Copyright: (C) 2013 Gilles Muller, INRIA/LIP6.
0009 // URL: https://coccinelle.gitlabpages.inria.fr/website
0010 // Comments:
0011 // Options: --no-includes --include-headers
0012 
0013 virtual org
0014 virtual report
0015 virtual context
0016 
0017 @r@
0018 constant c,c1;
0019 identifier i,i1;
0020 position p;
0021 @@
0022 
0023 (
0024  c1 + c - 1
0025 |
0026  c1@i1 +@p c@i
0027 )
0028 
0029 @s@
0030 constant r.c, r.c1;
0031 identifier i;
0032 expression e;
0033 @@
0034 
0035 (
0036 e | c@i
0037 |
0038 e & c@i
0039 |
0040 e |= c@i
0041 |
0042 e &= c@i
0043 |
0044 e | c1@i
0045 |
0046 e & c1@i
0047 |
0048 e |= c1@i
0049 |
0050 e &= c1@i
0051 )
0052 
0053 @depends on s@
0054 position r.p;
0055 constant c1,c2;
0056 @@
0057 
0058 * c1 +@p c2
0059 
0060 @script:python depends on s && org@
0061 p << r.p;
0062 @@
0063 
0064 cocci.print_main("sum of probable bitmasks, consider |",p)
0065 
0066 @script:python depends on s && report@
0067 p << r.p;
0068 @@
0069 
0070 msg = "WARNING: sum of probable bitmasks, consider |"
0071 coccilib.report.print_report(p[0],msg)