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