瀏覽代碼

gcc: Discard erroneous `task' and `task_implementation' decls.

* gcc-plugin/src/starpu.c (handle_task_attribute): Get rid of the
  attribute upon error.
  (handle_task_implementation_attribute): Likewise.  Always mark FN as
  used.
  (task_pointer_parameter_types): Remove extra quotes in warning
  message.

* gcc-plugin/tests/task-errors.c (bar): Add `unused' attribute.
  (my_task_almost, my_task_wrong_task_arg): New definitions.
  (my_task_nowhere): Move warning from the declaration to the
  definition.
Ludovic Courtès 14 年之前
父節點
當前提交
1710d101d0
共有 2 個文件被更改,包括 27 次插入5 次删除
  1. 14 2
      gcc-plugin/src/starpu.c
  2. 13 3
      gcc-plugin/tests/task-errors.c

+ 14 - 2
gcc-plugin/src/starpu.c

@@ -462,6 +462,10 @@ handle_task_attribute (tree *node, tree name, tree args,
 
   fn = *node;
 
+  /* Get rid of the `task' attribute by default so that FN isn't further
+     processed when it's erroneous.  */
+  *no_add_attrs = true;
+
   if (TREE_CODE (fn) != FUNCTION_DECL)
     error_at (DECL_SOURCE_LOCATION (fn),
 	      "%<task%> attribute only applies to functions");
@@ -537,6 +541,14 @@ handle_task_implementation_attribute (tree *node, tree name, tree args,
 
   loc = DECL_SOURCE_LOCATION (fn);
 
+  /* Get rid of the `task_implementation' attribute by default so that FN
+     isn't further processed when it's erroneous.  */
+  *no_add_attrs = true;
+
+  /* Mark FN as used to placate `-Wunused-function' when FN is erroneous
+     anyway.  */
+  TREE_USED (fn) = true;
+
   if (TREE_CODE (fn) != FUNCTION_DECL)
     error_at (loc,
 	      "%<task_implementation%> attribute only applies to functions");
@@ -569,7 +581,7 @@ handle_task_implementation_attribute (tree *node, tree name, tree args,
 		   remove_attribute (task_implementation_list_attribute_name,
 				     DECL_ATTRIBUTES (task_decl)));
 
-      TREE_USED (fn) = true;
+      TREE_USED (fn) = TREE_USED (task_decl);
 
       /* Keep the attribute.  */
       *no_add_attrs = false;
@@ -656,7 +668,7 @@ task_implementation_where (tree task_impl)
 	     warning and add a special attribute to TASK_IMPL to remember
 	     that we've already reported the problem.  */
 	  warning_at (DECL_SOURCE_LOCATION (task_impl), 0,
-		      "unsupported target %qE; task implementation won't be used",
+		      "unsupported target %E; task implementation won't be used",
 		      where);
 
 	  DECL_ATTRIBUTES (task_impl) =

+ 13 - 3
gcc-plugin/tests/task-errors.c

@@ -23,7 +23,7 @@ static void my_task_cpu (int foo, float *bar)    /* (error "type differs") */
 static void my_task_opencl (long foo, char *bar) /* (error "type differs") */
   __attribute__ ((task_implementation ("opencl", my_task)));
 
-static void my_task_nowhere (int foo, char *bar) /* (warning "unsupported target") */
+static void my_task_nowhere (int foo, char *bar)
   __attribute__ ((task_implementation ("does-not-exist", my_task)));
 
 static void my_task_not_quite (int foo, char *bar) /* (error "lacks the 'task' attribute") */
@@ -33,7 +33,7 @@ static int foo /* (error "only applies to function") */
   __attribute__ ((task_implementation ("cpu", my_task)));
 
 static int bar /* (error "only applies to function") */
-  __attribute__ ((task));
+  __attribute__ ((task, unused));
 
 static int not_a_task __attribute__ ((unused));
 
@@ -58,7 +58,7 @@ my_task_opencl (long foo, char *bar)
 }
 
 static void
-my_task_nowhere (int foo, char *bar)
+my_task_nowhere (int foo, char *bar)  /* (warning "unsupported target") */
 {
 }
 
@@ -71,3 +71,13 @@ static void
 my_task_almost (int foo, char *bar)
 {
 }
+
+static void
+my_task_wrong_task_arg (int foo, char *bar)
+{
+}
+
+static void
+my_task_wrong_target_arg (int foo, char *bar)
+{
+}