Преглед изворни кода

Coccinelle: add a script that looks for calls to starpu_task_submit() that are not checked against 0.

In the future, this script could probbaly be extended to apply to other functions as well.
It provides context, org, patch and report modes.
Cyril Roelandt пре 13 година
родитељ
комит
ce10d8c178

+ 101 - 0
tools/dev/experimental/unchecked_starpu_function_calls.cocci

@@ -0,0 +1,101 @@
+/*
+ * StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012 inria
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+/*
+ * 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.
+ */
+virtual context
+virtual org
+virtual patch
+virtual report
+
+@initialize:python depends on report || org@
+msg = "Unchecked call to starpu_task_submit()"
+
+@unchecked_starpu_func_call@
+identifier f;
+position p;
+@@
+f(...)
+{
+	...
+	starpu_task_submit@p(...);
+	...
+}
+
+
+// Context mode.
+@depends on unchecked_starpu_func_call && context@
+position unchecked_starpu_func_call.p;
+@@
+* starpu_task_submit@p(...);
+
+// Org mode.
+@script:python depends on unchecked_starpu_func_call && org@
+p << unchecked_starpu_func_call.p;
+@@
+coccilib.org.print_todo(p[0], msg)
+
+// Patch mode.
+@has_ret depends on unchecked_starpu_func_call@
+identifier unchecked_starpu_func_call.f;
+identifier ret;
+identifier starpu_func =~ "^starpu_";
+@@
+f(...)
+{
+	...
+	ret = starpu_func(...);
+	...
+}
+
+@depends on unchecked_starpu_func_call && has_ret && patch@
+identifier unchecked_starpu_func_call.f;
+identifier has_ret.ret;
+@@
+f(...)
+{
+...
+- starpu_task_submit(
++ ret = starpu_task_submit(
+...);
++ STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
+...
+}
+
+@depends on unchecked_starpu_func_call && !has_ret && patch@
+identifier unchecked_starpu_func_call.f;
+@@
+f(...)
+{
+...
+- starpu_task_submit(
++ int ret = starpu_task_submit(
+...);
++ STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
+
+...
+}
+
+// Report mode.
+@script:python depends on unchecked_starpu_func_call && report@
+p << unchecked_starpu_func_call.p;
+@@
+coccilib.report.print_report(p[0], msg)

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

@@ -0,0 +1,15 @@
+static void
+f(void)
+{
+	int err;
+	err = starpu_task_submit(task1);
+
+	starpu_task_submit(task2);
+	return;
+}
+
+static void
+g(void)
+{
+	starpu_task_submit(task);
+}