浏览代码

gcc: Improve error handling and tests for `#pragma starpu register'.

* gcc-plugin/src/starpu.c (handle_pragma_register): Return after
  `error_at' calls.  Change the assertion on the type of VAR into an
  error.

* gcc-plugin/tests/Makefile.am (gcc_tests): Remove `register-junk.c',
  `register-size-mismatch.c', `register-unbound.c', and
  `register-unterminated.c'.  Add `register-errors.c'.

* gcc-plugin/tests/register-errors.c: New file.

* gcc-plugin/tests/register.c (foo): New function.
  (main): Use it; increment the expected DATA_REGISTER_CALLS value.

* gcc-plugin/tests/run-test.in (%default-cflags): Remove `-dH', which
  caused GCC to stop upon the first error.
Ludovic Courtès 14 年之前
父节点
当前提交
f1a9dceb0b

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

@@ -302,18 +302,31 @@ handle_pragma_register (struct cpp_reader *reader)
 
   type = pragma_lex (&token);
   if (type == CPP_EOF)
-    error_at (loc, "unterminated %<starpu register%> pragma");
+    {
+      error_at (loc, "unterminated %<starpu register%> pragma");
+      return;
+    }
   else if (type != CPP_NAME)
-    error_at (loc, "identifier expected");
+    {
+      error_at (loc, "identifier expected");
+      return;
+    }
 
   /* Get the variable name.  */
   tree var_name = token;
   tree var = lookup_name (var_name);
   if (var == NULL_TREE || !DECL_P (var))
-    error_at (loc, "unbound variable %qE", var_name);
+    {
+      error_at (loc, "unbound variable %qE", var_name);
+      return;
+    }
 
-  gcc_assert (POINTER_TYPE_P (TREE_TYPE (var))
-	      || TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE);
+  if (!POINTER_TYPE_P (TREE_TYPE (var))
+      && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE)
+    {
+      error_at (loc, "%qE is neither a pointer nor an array", var_name);
+      return;
+    }
 
   if (TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE
       && !DECL_EXTERNAL (var)
@@ -376,7 +389,10 @@ handle_pragma_register (struct cpp_reader *reader)
 	error_at (loc, "junk after %<starpu register%> pragma");
     }
   else
-    error_at (loc, "integer expected");
+    {
+      error_at (loc, "integer expected");
+      return;
+    }
 
   /* If VAR is an array, take its address.  */
   tree pointer =

+ 1 - 4
gcc-plugin/tests/Makefile.am

@@ -18,10 +18,7 @@ gcc_tests =					\
   base.c					\
   pointers.c					\
   register.c					\
-  register-junk.c				\
-  register-size-mismatch.c			\
-  register-unbound.c				\
-  register-unterminated.c			\
+  register-errors.c				\
   scalar-tasks.c				\
   pointer-tasks.c
 

+ 11 - 2
gcc-plugin/tests/register-size-mismatch.c

@@ -14,7 +14,7 @@
    You should have received a copy of the GNU General Public License
    along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* Test whether `#pragma starpu register ...' leads to suitable errors.  */
+/* Test error handling for `#pragma starpu register ...'.  */
 
 #undef NDEBUG
 
@@ -23,9 +23,18 @@
 int
 main (int argc, char *argv[])
 {
-  static int x[123];
+#pragma starpu register /* (error "unterminated") */
 
+#pragma starpu register argv 234 junk right here /* (error "junk after") */
+
+  static int x[123] __attribute__ ((unused));
 #pragma starpu register x 234 /* (note "can be omitted") *//* (error "differs from actual size") */
 
+#pragma starpu register does_not_exit 123 /* (error "unbound variable") */
+
+#pragma starpu register argv /* (error "cannot determine size") */
+
+#pragma starpu register argc /* (error "neither a pointer nor an array") */
+
   return EXIT_SUCCESS;
 }

+ 0 - 29
gcc-plugin/tests/register-junk.c

@@ -1,29 +0,0 @@
-/* GCC-StarPU
-   Copyright (C) 2011 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
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   GCC-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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Test whether `#pragma starpu register ...' leads to suitable errors.  */
-
-#undef NDEBUG
-
-#include <lib.h>
-
-int
-main (int argc, char *argv[])
-{
-#pragma starpu register argv 234 junk right here /* (error "junk after") */
-
-  return EXIT_SUCCESS;
-}

+ 0 - 29
gcc-plugin/tests/register-unbound.c

@@ -1,29 +0,0 @@
-/* GCC-StarPU
-   Copyright (C) 2011 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
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   GCC-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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Test whether `#pragma starpu register ...' leads to suitable errors.  */
-
-#undef NDEBUG
-
-#include <lib.h>
-
-int
-main (int argc, char *argv[])
-{
-#pragma starpu register does_not_exit 123 /* (error "unbound variable") */
-
-  return EXIT_SUCCESS;
-}

+ 0 - 29
gcc-plugin/tests/register-unterminated.c

@@ -1,29 +0,0 @@
-/* GCC-StarPU
-   Copyright (C) 2011 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
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-
-   GCC-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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Test whether `#pragma starpu register ...' leads to suitable errors.  */
-
-#undef NDEBUG
-
-#include <lib.h>
-
-int
-main (int argc, char *argv[])
-{
-#pragma starpu register /* (error "unterminated") */
-
-  return EXIT_SUCCESS;
-}

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

@@ -20,6 +20,17 @@
 
 #include <lib.h>
 
+static void
+foo (void)
+{
+  char x[] = { 1, 2, 3 };
+
+  expected_register_arguments.pointer = x;
+  expected_register_arguments.elements = sizeof x;
+  expected_register_arguments.element_size = 1;
+#pragma starpu register x /* (warning "considered unsafe") */
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -64,7 +75,9 @@ main (int argc, char *argv[])
 #undef ARGV
 #undef N
 
-  assert (data_register_calls == 6);
+  foo ();
+
+  assert (data_register_calls == 7);
 
   free (y);
 

+ 2 - 2
gcc-plugin/tests/run-test.in

@@ -42,7 +42,7 @@ exec "${GUILE-@GUILE@}" -l "$0"    \
 
 ;;; Commentary:
 ;;;
-;;; Test machinery similary to the DejaGNU-based test framework used in GCC.
+;;; Test machinery similar to the DejaGNU-based test framework used in GCC.
 ;;; In a nutshell, this program compiles code with GCC and makes sure
 ;;; warnings and errors are as appear in source code comments.
 ;;;
@@ -80,7 +80,7 @@ exec "${GUILE-@GUILE@}" -l "$0"    \
     ;; the real file name.
     ,(string-append "-fplugin=" %builddir "/../src/.libs/starpu.so")
 
-    "-dH" "-fdump-tree-gimple" "-Wall"))
+    "-fdump-tree-gimple" "-Wall"))
 
 (define %default-ldflags
   `(,(string-append "-L" %srcdir "/../../src")))