unchecked_starpu_function_calls.cocci 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. /*
  17. * The return values of functions such as starpu_init(), starpu_task_submit(),
  18. * starpu_task_wait() should _always_ be checked.
  19. */
  20. virtual context
  21. virtual org
  22. virtual patch
  23. virtual report
  24. @initialize:python depends on report || org@
  25. msg = "Unchecked call to %s"
  26. from re import sub
  27. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  28. @unchecked_starpu_func_call@
  29. identifier f;
  30. position p;
  31. identifier starpu_function =~ "\bstarpu_(init|task_(submit|wait))\b";
  32. @@
  33. f(...)
  34. {
  35. <+...
  36. starpu_function@p(...);
  37. ...+>
  38. }
  39. // Context mode.
  40. @depends on unchecked_starpu_func_call && context@
  41. position unchecked_starpu_func_call.p;
  42. identifier unchecked_starpu_func_call.starpu_function;
  43. identifier unchecked_starpu_func_call.f;
  44. @@
  45. f(...)
  46. {
  47. <+...
  48. * starpu_function@p(...);
  49. ...+>
  50. }
  51. // Org mode.
  52. @script:python depends on unchecked_starpu_func_call && org@
  53. f << unchecked_starpu_func_call.starpu_function;
  54. p << unchecked_starpu_func_call.p;
  55. @@
  56. coccilib.org.print_todo(p[0], orgmsg % f)
  57. // Patch mode.
  58. @has_ret depends on unchecked_starpu_func_call@
  59. identifier unchecked_starpu_func_call.f;
  60. identifier ret;
  61. identifier starpu_func =~ "^starpu_";
  62. @@
  63. f(...)
  64. {
  65. ...
  66. int ret;
  67. ...
  68. ret = starpu_func(...);
  69. ...
  70. }
  71. @script:python stringify depends on patch@
  72. function_name << unchecked_starpu_func_call.starpu_function;
  73. starpu_function_name;
  74. @@
  75. coccinelle.starpu_function_name = '"'+str(function_name)+'"'
  76. // In this rule, "ret" is probably a good choice. This should be checked when
  77. // reviewing the patches, though.
  78. @depends on unchecked_starpu_func_call && has_ret && patch@
  79. identifier unchecked_starpu_func_call.f;
  80. identifier has_ret.ret;
  81. identifier unchecked_starpu_func_call.starpu_function;
  82. identifier stringify.starpu_function_name;
  83. @@
  84. f(...)
  85. {
  86. <...
  87. - starpu_function(
  88. + ret = starpu_function(
  89. ...);
  90. + STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
  91. ...>
  92. }
  93. // In this rule, we use a variable called "ret" that is probably not declared.
  94. // Obviously, the patches should be read before being committed !
  95. @depends on unchecked_starpu_func_call && !has_ret && patch@
  96. identifier unchecked_starpu_func_call.f;
  97. identifier unchecked_starpu_func_call.starpu_function;
  98. identifier stringify.starpu_function_name;
  99. @@
  100. f(...)
  101. {
  102. <...
  103. - starpu_function(
  104. + ret = starpu_function(
  105. ...);
  106. + STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
  107. ...>
  108. }
  109. // Report mode.
  110. @script:python depends on unchecked_starpu_func_call && report@
  111. f << unchecked_starpu_func_call.starpu_function;
  112. p << unchecked_starpu_func_call.p;
  113. @@
  114. coccilib.report.print_report(p[0], msg % f)