destroy_task_on_error.cocci 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2020 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. * When the submission of a task fails, StarPU cannot destroy the task, even if
  18. * the destroy flag is set. So we have to destroy it ourselves while handling
  19. * the error.
  20. *
  21. * TODO: match if statments without braces.
  22. */
  23. virtual context
  24. virtual org
  25. virtual patch
  26. virtual report
  27. @initialize:python depends on org || report@
  28. msg = "Warning: in %s(): "
  29. msg+= "\"%s\" should probably be destroyed in the body of the if statement"
  30. from re import sub
  31. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  32. @r@
  33. local idexpression t;
  34. identifier err;
  35. identifier f;
  36. position p;
  37. @@
  38. f(...)
  39. {
  40. <+...
  41. (
  42. err = starpu_task_submit(t);
  43. |
  44. int err = starpu_task_submit(t);
  45. )
  46. if@p(
  47. (
  48. err == -ENODEV
  49. |
  50. err != 0
  51. |
  52. STARPU_UNLIKELY(err == -ENODEV)
  53. |
  54. STARPU_UNLIKELY(err != 0)
  55. )
  56. )
  57. {
  58. ... when != starpu_task_destroy(t);
  59. when != exit(...);
  60. when != STARPU_ASSERT(...);
  61. when != return 77;
  62. }
  63. ...+>
  64. }
  65. // Context mode.
  66. @depends on r && context@
  67. position r.p;
  68. @@
  69. *if@p(...) { ... }
  70. // Org mode.
  71. @script:python depends on r && org@
  72. p << r.p;
  73. t << r.t;
  74. f << r.f;
  75. @@
  76. coccilib.org.print_todo(p[0], orgmsg % (f,t))
  77. // Patch mode.
  78. // XXX: Instead of "..." we could use a statement list (statement list SS). But
  79. // it does not seem to work with if there is a "return" statement in the body
  80. // of the if condition.
  81. // Using "..." makes the patch ugly, but this may be fixed in a future version
  82. // of spatch.
  83. @depends on r && patch@
  84. local idexpression r.t;
  85. position r.p;
  86. identifier r.f;
  87. @@
  88. f(...)
  89. {
  90. <+...
  91. if@p (...)
  92. (
  93. {
  94. ...
  95. + t->destroy = 0;
  96. + starpu_task_destroy(t);
  97. return ...;
  98. }
  99. |
  100. {
  101. ...
  102. + t->destroy = 0;
  103. + starpu_task_destroy(t);
  104. }
  105. )
  106. ...+>
  107. }
  108. // Report mode.
  109. @script:python depends on r && report@
  110. p << r.p;
  111. t << r.t;
  112. f << r.f;
  113. @@
  114. coccilib.report.print_report(p[0], msg % (f,t))