Quellcode durchsuchen

gcc: Allow use of a PARM_DECL as the count argument of pragma `register'.

* gcc-plugin/src/starpu.c (handle_pragma_register): Leave the chain of
  COUNT_ARG unchanged.  This fixes a bug whereby passing a PARM_DECL as
  the `count' argument would screw the parameter list.
  Reported by Ludovic Stordeur <ludovic.stordeur@inria.fr>.

* gcc-plugin/tests/register.c (baz): New function.
  (main): Call it.  Update expected call count.
Ludovic Courtès vor 13 Jahren
Ursprung
Commit
076cd345d1
2 geänderte Dateien mit 14 neuen und 5 gelöschten Zeilen
  1. 1 4
      gcc-plugin/src/starpu.c
  2. 13 1
      gcc-plugin/tests/register.c

+ 1 - 4
gcc-plugin/src/starpu.c

@@ -609,10 +609,7 @@ handle_pragma_register (struct cpp_reader *reader)
   /* Second argument is optional but should be an integer.  */
   count_arg = (args == NULL_TREE) ? NULL_TREE : TREE_VALUE (args);
   if (args != NULL_TREE)
-    {
-      args = TREE_CHAIN (args);
-      TREE_CHAIN (count_arg) = NULL_TREE;
-    }
+    args = TREE_CHAIN (args);
 
   if (count_arg == NULL_TREE)
     {

+ 13 - 1
gcc-plugin/tests/register.c

@@ -40,6 +40,17 @@ bar (float *p, int s)
 #pragma starpu register p s
 }
 
+/* Same as above, but with arguments reversed, to make sure using S doesn't
+   mutate the parameter list.  */
+static void
+baz (int s, float *p)
+{
+  expected_register_arguments.pointer = p;
+  expected_register_arguments.elements = s;
+  expected_register_arguments.element_size = sizeof *p;
+#pragma starpu register p s
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -96,6 +107,7 @@ main (int argc, char *argv[])
 
   foo ();
   bar ((float *) argv, argc);
+  baz (argc, (float *) argv);
 
   expected_register_arguments.pointer = argv;
   expected_register_arguments.elements = argc;
@@ -134,7 +146,7 @@ main (int argc, char *argv[])
   expected_register_arguments.element_size = sizeof m3d[0];
 #pragma starpu register m3d
 
-  assert (data_register_calls == 16);
+  assert (data_register_calls == 17);
 
   free (y);