unchecked_starpu_function_calls.cocci 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. @unchecked_starpu_func_call@
  28. identifier f;
  29. position p;
  30. identifier starpu_function =~ "\bstarpu_(init|task_(submit|wait))\b";
  31. @@
  32. f(...)
  33. {
  34. <+...
  35. starpu_function@p(...);
  36. ...+>
  37. }
  38. // Context mode.
  39. @depends on unchecked_starpu_func_call && context@
  40. position unchecked_starpu_func_call.p;
  41. identifier unchecked_starpu_func_call.starpu_function;
  42. identifier unchecked_starpu_func_call.f;
  43. @@
  44. f(...)
  45. {
  46. <+...
  47. * starpu_function@p(...);
  48. ...+>
  49. }
  50. // Org mode.
  51. @script:python depends on unchecked_starpu_func_call && org@
  52. f << unchecked_starpu_func_call.starpu_function;
  53. p << unchecked_starpu_func_call.p;
  54. @@
  55. coccilib.org.print_todo(p[0], msg % f)
  56. // Patch mode.
  57. @has_ret depends on unchecked_starpu_func_call@
  58. identifier unchecked_starpu_func_call.f;
  59. identifier ret;
  60. identifier starpu_func =~ "^starpu_";
  61. @@
  62. f(...)
  63. {
  64. ...
  65. int ret;
  66. ...
  67. ret = starpu_func(...);
  68. ...
  69. }
  70. @script:python stringify depends on patch@
  71. function_name << unchecked_starpu_func_call.starpu_function;
  72. starpu_function_name;
  73. @@
  74. coccinelle.starpu_function_name = '"'+str(function_name)+'"'
  75. @depends on unchecked_starpu_func_call && has_ret && patch@
  76. identifier unchecked_starpu_func_call.f;
  77. identifier has_ret.ret;
  78. identifier unchecked_starpu_func_call.starpu_function;
  79. identifier stringify.starpu_function_name;
  80. @@
  81. f(...)
  82. {
  83. <...
  84. - starpu_function(
  85. + ret = starpu_function(
  86. ...);
  87. + STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
  88. ...>
  89. }
  90. @depends on unchecked_starpu_func_call && !has_ret && patch@
  91. identifier unchecked_starpu_func_call.f;
  92. identifier unchecked_starpu_func_call.starpu_function;
  93. identifier stringify.starpu_function_name;
  94. @@
  95. f(...)
  96. {
  97. <...
  98. - starpu_function(
  99. + int ret = starpu_function(
  100. ...);
  101. + STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
  102. ...>
  103. }
  104. // Report mode.
  105. @script:python depends on unchecked_starpu_func_call && report@
  106. f << unchecked_starpu_func_call.starpu_function;
  107. p << unchecked_starpu_func_call.p;
  108. @@
  109. coccilib.report.print_report(p[0], msg % f)