Browse Source

gcc: Raise an error when `STARPU_NMAXBUFS' is reached.

* gcc-plugin/src/starpu.c (pointer_type_p, count): New functions.
  (handle_task_attribute): Emit an error when more than STARPU_NMAXBUFS
  pointer parameters are in use.
  (task_pointer_parameter_types)[is_pointer]: Remove.  Use
  `pointer_type_p' instead.

* gcc-plugin/tests/task-errors.c (my_task_with_too_many_pointer_params):
  New declaration.
Ludovic Courtès 13 years ago
parent
commit
ca0dc0aceb
2 changed files with 39 additions and 7 deletions
  1. 27 6
      gcc-plugin/src/starpu.c
  2. 12 1
      gcc-plugin/tests/task-errors.c

+ 27 - 6
gcc-plugin/src/starpu.c

@@ -206,6 +206,14 @@ void_type_p (const_tree lst)
   return VOID_TYPE_P (TREE_VALUE (lst));
 }
 
+/* Return true if LST holds a pointer type.  */
+
+bool
+pointer_type_p (const_tree lst)
+{
+  gcc_assert (TREE_CODE (lst) == TREE_LIST);
+  return POINTER_TYPE_P (TREE_VALUE (lst));
+}
 
 
 /* Debugging helpers.  */
@@ -323,6 +331,19 @@ for_each (void (*func) (tree), tree t)
     func (TREE_VALUE (lst));
 }
 
+static size_t
+count (bool (*pred) (const_tree), const_tree t)
+{
+  size_t result;
+  const_tree lst;
+
+  for (lst = t, result = 0; lst != NULL_TREE; lst = TREE_CHAIN (lst))
+    if (pred (lst))
+      result++;
+
+  return result;
+}
+
 
 /* Pragmas.  */
 
@@ -702,6 +723,11 @@ handle_task_attribute (tree *node, tree name, tree args,
 	error_at (DECL_SOURCE_LOCATION (fn),
 		  "task return type must be %<void%>");
 
+      if (count (pointer_type_p, TYPE_ARG_TYPES (TREE_TYPE (fn)))
+	  > STARPU_NMAXBUFS)
+	error_at (DECL_SOURCE_LOCATION (fn),
+		  "maximum number of pointer parameters exceeded");
+
       /* This is a function declaration for something local to this
 	 translation unit, so add the `task' attribute to FN.  */
       *no_add_attrs = false;
@@ -938,12 +964,7 @@ task_implementation_list (const_tree task_decl)
 static tree
 task_pointer_parameter_types (const_tree task_decl)
 {
-  bool is_pointer (const_tree item)
-  {
-    return POINTER_TYPE_P (TREE_VALUE (item));
-  }
-
-  return filter (is_pointer, TYPE_ARG_TYPES (TREE_TYPE (task_decl)));
+  return filter (pointer_type_p, TYPE_ARG_TYPES (TREE_TYPE (task_decl)));
 }
 
 /* Return the StarPU integer constant corresponding to string TARGET.  */

+ 12 - 1
gcc-plugin/tests/task-errors.c

@@ -1,5 +1,5 @@
 /* GCC-StarPU
-   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+   Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
 
    GCC-StarPU is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -60,6 +60,17 @@ void my_task_that_invokes_task (int x, char *y)
 void my_task_that_invokes_task_cpu (int x, char *y)
   __attribute__ ((task_implementation ("cpu", my_task_that_invokes_task)));
 
+/* XXX: In practice this test fails for large values of `STARPU_NMAXBUFS'.  */
+void my_task_with_too_many_pointer_params (/* (error "maximum .* exceeded") */
+					   char *x1, char *x2, char *x3,
+					   char *x4, char *x5, char *x6,
+					   char *x7, char *x8, char *x9,
+					   char *xa, char *xb, char *xc,
+					   char *xd, char *xe, char *xf,
+					   char *xg, char *xh, char *xi)
+  __attribute__ ((task));
+
+
 
 static void
 my_task_cpu (int foo, float *bar)