unchecked_starpu_function_calls.cocci 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. This semantic patch looks for
  20. * calls to starpu_task_submit() where the return value is ignored. It could
  21. * probably be extended to apply to other functions as well.
  22. */
  23. virtual context
  24. virtual org
  25. virtual patch
  26. virtual report
  27. @initialize:python depends on report || org@
  28. msg = "Unchecked call to starpu_task_submit()"
  29. @unchecked_starpu_func_call@
  30. identifier f;
  31. position p;
  32. @@
  33. f(...)
  34. {
  35. ...
  36. starpu_task_submit@p(...);
  37. ...
  38. }
  39. // Context mode.
  40. @depends on unchecked_starpu_func_call && context@
  41. position unchecked_starpu_func_call.p;
  42. @@
  43. * starpu_task_submit@p(...);
  44. // Org mode.
  45. @script:python depends on unchecked_starpu_func_call && org@
  46. p << unchecked_starpu_func_call.p;
  47. @@
  48. coccilib.org.print_todo(p[0], msg)
  49. // Patch mode.
  50. @has_ret depends on unchecked_starpu_func_call@
  51. identifier unchecked_starpu_func_call.f;
  52. identifier ret;
  53. identifier starpu_func =~ "^starpu_";
  54. @@
  55. f(...)
  56. {
  57. ...
  58. ret = starpu_func(...);
  59. ...
  60. }
  61. @depends on unchecked_starpu_func_call && has_ret && patch@
  62. identifier unchecked_starpu_func_call.f;
  63. identifier has_ret.ret;
  64. @@
  65. f(...)
  66. {
  67. ...
  68. - starpu_task_submit(
  69. + ret = starpu_task_submit(
  70. ...);
  71. + STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  72. ...
  73. }
  74. @depends on unchecked_starpu_func_call && !has_ret && patch@
  75. identifier unchecked_starpu_func_call.f;
  76. @@
  77. f(...)
  78. {
  79. ...
  80. - starpu_task_submit(
  81. + int ret = starpu_task_submit(
  82. ...);
  83. + STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  84. ...
  85. }
  86. // Report mode.
  87. @script:python depends on unchecked_starpu_func_call && report@
  88. p << unchecked_starpu_func_call.p;
  89. @@
  90. coccilib.report.print_report(p[0], msg)