destroy_task_on_error.cocci 2.2 KB

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