uninitialized_var.cocci 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. ///
  3. /// Please, don't reintroduce uninitialized_var().
  4. ///
  5. /// From Documentation/process/deprecated.rst,
  6. /// commit 4b19bec97c88 ("docs: deprecated.rst: Add uninitialized_var()"):
  7. /// For any compiler warnings about uninitialized variables, just add
  8. /// an initializer. Using warning-silencing tricks is dangerous as it
  9. /// papers over real bugs (or can in the future), and suppresses unrelated
  10. /// compiler warnings (e.g. "unused variable"). If the compiler thinks it
  11. /// is uninitialized, either simply initialize the variable or make compiler
  12. /// changes. Keep in mind that in most cases, if an initialization is
  13. /// obviously redundant, the compiler's dead-store elimination pass will make
  14. /// sure there are no needless variable writes.
  15. ///
  16. /// Later, commit 3942ea7a10c9 ("deprecated.rst: Remove now removed
  17. /// uninitialized_var") removed this section because all initializations of
  18. /// this kind were cleaned-up from the kernel. This cocci rule checks that
  19. /// the macro is not explicitly or implicitly reintroduced.
  20. ///
  21. // Confidence: High
  22. // Copyright: (C) 2020 Denis Efremov ISPRAS
  23. // Options: --no-includes --include-headers
  24. //
  25. virtual context
  26. virtual report
  27. virtual org
  28. @r@
  29. identifier var;
  30. type T;
  31. position p;
  32. @@
  33. (
  34. * T var =@p var;
  35. |
  36. * T var =@p *(&(var));
  37. |
  38. * var =@p var
  39. |
  40. * var =@p *(&(var))
  41. )
  42. @script:python depends on report@
  43. p << r.p;
  44. @@
  45. coccilib.report.print_report(p[0], "WARNING this kind of initialization is deprecated")
  46. @script:python depends on org@
  47. p << r.p;
  48. @@
  49. coccilib.org.print_todo(p[0], "WARNING this kind of initialization is deprecated")