Преглед на файлове

Coccinelle: extend unchecked_starpu_function_calls so that it also works with starpu_init and starpu_task_wait.

Cyril Roelandt преди 13 години
родител
ревизия
94e1eb7ec0
променени са 2 файла, в които са добавени 49 реда и са изтрити 24 реда
  1. 45 24
      tools/dev/experimental/unchecked_starpu_function_calls.cocci
  2. 4 0
      tools/dev/experimental/unchecked_starpu_function_calls_test.c

+ 45 - 24
tools/dev/experimental/unchecked_starpu_function_calls.cocci

@@ -17,41 +17,49 @@
 
 /*
  * The return values of functions such as starpu_init(), starpu_task_submit(),
- * starpu_task_wait() should _always_ be checked. This semantic patch looks for
- * calls to starpu_task_submit() where the return value is ignored. It could
- * probably be extended to apply to other functions as well.
+ * starpu_task_wait() should _always_ be checked.
  */
+
 virtual context
 virtual org
 virtual patch
 virtual report
 
 @initialize:python depends on report || org@
-msg = "Unchecked call to starpu_task_submit()"
+msg = "Unchecked call to %s"
 
 @unchecked_starpu_func_call@
 identifier f;
 position p;
+identifier starpu_function =~ "\bstarpu_(init|task_(submit|wait))\b";
 @@
 f(...)
 {
-	...
-	starpu_task_submit@p(...);
-	...
+<+...
+starpu_function@p(...);
+...+>
 }
 
 
 // Context mode.
 @depends on unchecked_starpu_func_call && context@
 position unchecked_starpu_func_call.p;
+identifier unchecked_starpu_func_call.starpu_function;
+identifier unchecked_starpu_func_call.f;
 @@
-* starpu_task_submit@p(...);
+f(...)
+{
+<+...
+* starpu_function@p(...);
+...+>
+}
 
 // Org mode.
 @script:python depends on unchecked_starpu_func_call && org@
+f << unchecked_starpu_func_call.starpu_function;
 p << unchecked_starpu_func_call.p;
 @@
-coccilib.org.print_todo(p[0], msg)
+coccilib.org.print_todo(p[0], msg % f)
 
 // Patch mode.
 @has_ret depends on unchecked_starpu_func_call@
@@ -61,41 +69,54 @@ identifier starpu_func =~ "^starpu_";
 @@
 f(...)
 {
-	...
-	ret = starpu_func(...);
-	...
+...
+int ret;
+...
+ret = starpu_func(...);
+...
 }
 
+@script:python stringify depends on patch@
+function_name << unchecked_starpu_func_call.starpu_function;
+starpu_function_name;
+@@
+coccinelle.starpu_function_name = '"'+str(function_name)+'"'
+
+
 @depends on unchecked_starpu_func_call && has_ret && patch@
 identifier unchecked_starpu_func_call.f;
 identifier has_ret.ret;
+identifier unchecked_starpu_func_call.starpu_function;
+identifier stringify.starpu_function_name;
 @@
 f(...)
 {
-...
-- starpu_task_submit(
-+ ret = starpu_task_submit(
+<...
+- starpu_function(
++ ret = starpu_function(
 ...);
-+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
-...
++ STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
+...>
 }
 
 @depends on unchecked_starpu_func_call && !has_ret && patch@
 identifier unchecked_starpu_func_call.f;
+identifier unchecked_starpu_func_call.starpu_function;
+identifier stringify.starpu_function_name;
 @@
 f(...)
 {
-...
-- starpu_task_submit(
-+ int ret = starpu_task_submit(
+<...
+- starpu_function(
++ int ret = starpu_function(
 ...);
-+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
-
-...
++ STARPU_CHECK_RETURN_VALUE(ret, starpu_function_name);
+...>
 }
 
 // Report mode.
 @script:python depends on unchecked_starpu_func_call && report@
+f << unchecked_starpu_func_call.starpu_function;
 p << unchecked_starpu_func_call.p;
 @@
-coccilib.report.print_report(p[0], msg)
+coccilib.report.print_report(p[0], msg % f)

+ 4 - 0
tools/dev/experimental/unchecked_starpu_function_calls_test.c

@@ -11,5 +11,9 @@ f(void)
 static void
 g(void)
 {
+
+	starpu_init(NULL);
 	starpu_task_submit(task);
+
+	starpu_task_wait(task);
 }