orplus.cocci 1.0 KB

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