unchecked_starpu_function_calls.cocci 3.1 KB

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