Преглед на файлове

gcc: Parse with `c_lex_with_flags' to distinguish adjacent strings.

* gcc-plugin/src/c-expr.y (yylex): Use `cpp_peek_token' and
  `c_lex_with_flags' instead of `pragma_lex'.

* gcc-plugin/src/starpu.c (handle_pragma_register): Report an error when
  PTR_TYPE is null.

* gcc-plugin/tests/register.c (main): Remove test for string literals.
* gcc-plugin/tests/register-errors.c (main): Make sure string literals
  are rejected.
Ludovic Courtès преди 13 години
родител
ревизия
769037ee28
променени са 4 файла, в които са добавени 28 реда и са изтрити 10 реда
  1. 18 4
      gcc-plugin/src/c-expr.y
  2. 7 0
      gcc-plugin/src/starpu.c
  3. 2 0
      gcc-plugin/tests/register-errors.c
  4. 1 6
      gcc-plugin/tests/register.c

+ 18 - 4
gcc-plugin/src/c-expr.y

@@ -132,6 +132,8 @@
   yylex (YYSTYPE *lvalp)
   {
     int ret;
+    enum cpp_ttype type;
+    location_t loc;
 
 #ifdef __cplusplus
     if (cpplib_bison_token_map[CPP_NAME] != YCPP_NAME)
@@ -143,11 +145,23 @@
       }
 #endif
 
-    ret = pragma_lex (lvalp);
-    if (ret < sizeof cpplib_bison_token_map / sizeof cpplib_bison_token_map[0])
-      ret = cpplib_bison_token_map[ret];
-    else
+    /* First check whether EOL is reached, because the EOL token needs to be
+       left to the C parser.  */
+    type = cpp_peek_token (parse_in, 0)->type;
+    if (type == CPP_PRAGMA_EOL)
       ret = -1;
+    else
+      {
+	/* Tell the lexer to not concatenate adjacent strings like cpp and
+	   `pragma_lex' normally do, because we want to be able to
+	   distinguish adjacent STRING_CST.  */
+	type = c_lex_with_flags (lvalp, &loc, NULL, C_LEX_STRING_NO_JOIN);
+
+	if (type < sizeof cpplib_bison_token_map / sizeof cpplib_bison_token_map[0])
+	  ret = cpplib_bison_token_map[type];
+	else
+	  ret = -1;
+      }
 
     return ret;
   }

+ 7 - 0
gcc-plugin/src/starpu.c

@@ -769,6 +769,13 @@ handle_pragma_register (struct cpp_reader *reader)
   else
     ptr_type = TREE_TYPE (ptr);
 
+  if (ptr_type == NULL_TREE)
+    {
+      /* PTR is a type-less thing, such as a STRING_CST.  */
+      error_at (loc, "invalid %<register%> argument");
+      return;
+    }
+
   if (!POINTER_TYPE_P (ptr_type)
       && TREE_CODE (ptr_type) != ARRAY_TYPE)
     {

+ 2 - 0
gcc-plugin/tests/register-errors.c

@@ -54,5 +54,7 @@ main (int argc, char *argv[])
 
 #pragma starpu register void_pointer 123 /* (error "not allowed") */
 
+#pragma starpu register "hello"		   /* (error "invalid .*argument") */
+
   return EXIT_SUCCESS;
 }

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

@@ -172,12 +172,7 @@ main (int argc, char *argv[])
   expected_register_arguments.element_size = sizeof m3d[0];
 #pragma starpu register m3d
 
-  expected_register_arguments.pointer = "hello";
-  expected_register_arguments.elements = sizeof "hello";
-  expected_register_arguments.element_size = 1;
-#pragma starpu register "hello"
-
-  assert (data_register_calls == 18);
+  assert (data_register_calls == 17);
 
   free (y);