I've committed this new testcase for openacc routines. It showed up some
discreprancies in the diagnostics from the C and C++ FE's, hence the changes
there to unifiy the wording. I also fixed up a couple of the libgomp tests to
avoid an uninteresting warning (which tickles a defect in the offloading
machinery not propagating the diagnostic formatting options).
nathan
2015-08-17 Nathan Sidwell <nat...@codesourcery.com>
c/
* c-parser.c (c_finish_oacc_routine): Add named parameter. Adjust
all callers.
(c_parser_declaration_or_fndef): Add missing c_finish_oacc_routine
call.
(c_parser_oacc_routine): Adjust error messages to match C++ FE.
cp/
* parser.c (cp_parser_finish_oacc_routine): Adjust to match
errors from C FE.
testsuite/
* c-c++-common/goacc/routine-5.c: New.
libgomp/
* testsuite/libgomp.oacc-c-c++-common/routine-1.c: Avoid
uninteresting warning.
* testsuite/libgomp.oacc-c-c++-common/routine-1.c: Likewise.
Index: gcc/c/c-parser.c
===================================================================
--- gcc/c/c-parser.c (revision 226952)
+++ gcc/c/c-parser.c (working copy)
@@ -1762,7 +1762,7 @@ finish_oacc_declare (tree fnbody, tree d
static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
-static void c_finish_oacc_routine (c_parser *, tree, tree, bool);
+static void c_finish_oacc_routine (c_parser *, tree, tree, bool, bool);
/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
6.7, 6.9.1). If FNDEF_OK is true, a function definition is
@@ -1903,6 +1903,9 @@ c_parser_declaration_or_fndef (c_parser
pedwarn (here, 0, "empty declaration");
}
c_parser_consume_token (parser);
+ if (oacc_routine_clauses)
+ c_finish_oacc_routine (parser, NULL_TREE,
+ oacc_routine_clauses, false, false);
return;
}
@@ -2021,7 +2024,7 @@ c_parser_declaration_or_fndef (c_parser
omp_declare_simd_clauses);
if (oacc_routine_clauses)
c_finish_oacc_routine (parser, NULL_TREE,
- oacc_routine_clauses, false);
+ oacc_routine_clauses, false, false);
c_parser_skip_to_end_of_block_or_statement (parser);
return;
}
@@ -2138,7 +2141,8 @@ c_parser_declaration_or_fndef (c_parser
finish_init ();
}
if (oacc_routine_clauses)
- c_finish_oacc_routine (parser, d, oacc_routine_clauses, false);
+ c_finish_oacc_routine (parser, d, oacc_routine_clauses,
+ false, false);
if (d != error_mark_node)
{
maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
@@ -2184,7 +2188,8 @@ c_parser_declaration_or_fndef (c_parser
temp_pop_parm_decls ();
}
if (oacc_routine_clauses)
- c_finish_oacc_routine (parser, d, oacc_routine_clauses, false);
+ c_finish_oacc_routine (parser, d, oacc_routine_clauses,
+ false, false);
if (d)
finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
@@ -2298,7 +2303,7 @@ c_parser_declaration_or_fndef (c_parser
omp_declare_simd_clauses);
if (oacc_routine_clauses)
c_finish_oacc_routine (parser, current_function_decl,
- oacc_routine_clauses, true);
+ oacc_routine_clauses, false, true);
DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
@@ -13306,7 +13311,8 @@ c_parser_oacc_routine (c_parser *parser,
decl = lookup_name (token->value);
if (!decl)
{
- error_at (token->location, "%qE undeclared", token->value);
+ error_at (token->location, "%qE has not been declared",
+ token->value);
decl = error_mark_node;
}
c_parser_consume_token (parser);
@@ -13327,7 +13333,7 @@ c_parser_oacc_routine (c_parser *parser,
clauses = tree_cons (c_head, clauses, NULL_TREE);
if (decl)
- c_finish_oacc_routine (parser, decl, clauses, false);
+ c_finish_oacc_routine (parser, decl, clauses, true, false);
else
c_parser_declaration_or_fndef (parser, true, false, false, false,
true, NULL, vNULL, clauses);
@@ -13339,14 +13345,16 @@ c_parser_oacc_routine (c_parser *parser,
static void
c_finish_oacc_routine (c_parser *ARG_UNUSED (parser),
- tree fndecl, tree clauses, bool is_defn)
+ tree fndecl, tree clauses, bool named, bool is_defn)
{
location_t loc = OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses));
if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL)
{
if (fndecl != error_mark_node)
- error_at (loc, "%<#pragma acc routine%> does not refer to a function");
+ error_at (loc, "%<#pragma acc routine%> %s",
+ named ? "does not refer to a function"
+ : "not followed by function");
return;
}
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 226952)
+++ gcc/cp/parser.c (working copy)
@@ -34318,24 +34318,19 @@ cp_parser_finish_oacc_routine (cp_parser
{
location_t loc = OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses));
- if (!fndecl)
- {
- error ("%<#pragma oacc routine%> not immediately followed by "
- "function declaration or definition");
- return;
- }
-
- if (named && is_overloaded_fn (fndecl)
+ if (named && fndecl && is_overloaded_fn (fndecl)
&& (TREE_CODE (fndecl) != FUNCTION_DECL
|| DECL_FUNCTION_TEMPLATE_P (fndecl)))
{
- error_at (loc, "%D names a set of overloads", OVL_CURRENT (fndecl));
+ error_at (loc, "%<#pragma acc routine%> names a set of overloads");
return;
}
- if (TREE_CODE (fndecl) != FUNCTION_DECL)
+ if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL)
{
- error_at (loc, "%D is not a function", fndecl);
+ error_at (loc, "%<#pragma acc routine%> %s",
+ named ? "does not refer to a function"
+ : "not followed by function");
return;
}
@@ -34343,7 +34338,8 @@ cp_parser_finish_oacc_routine (cp_parser
namespaces? */
if (named && !DECL_NAMESPACE_SCOPE_P (fndecl))
{
- error_at (loc, "%D is not at namespace scope", fndecl);
+ error_at (loc, "%<#pragma acc routine%> does not refer to a"
+ " namespace scope function");
return;
}
@@ -34399,6 +34395,9 @@ cp_parser_oacc_routine (cp_parser *parse
/*declarator_p=*/false,
/*optional_p=*/false);
decl = cp_parser_lookup_name_simple (parser, id, token->location);
+ if (id != error_mark_node && decl == error_mark_node)
+ cp_parser_name_lookup_error (parser, id, decl, NLE_NULL,
+ token->location);
if (decl == error_mark_node
|| !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
Index: gcc/testsuite/c-c++-common/goacc/routine-5.c
===================================================================
--- gcc/testsuite/c-c++-common/goacc/routine-5.c (revision 0)
+++ gcc/testsuite/c-c++-common/goacc/routine-5.c (working copy)
@@ -0,0 +1,20 @@
+/* Test invalid use of clauses with routine. */
+/* { dg-do compile } */
+/* { dg-additional-options "-W */
+
+void Bar ();
+
+void Foo ()
+{
+ Bar ();
+}
+
+#pragma acc routine (Bar) // { dg-error "must be applied before use" }
+
+#pragma acc routine (Foo) gang // { dg-error "must be applied before definition" }
+
+#pragma acc routine (Baz) // { dg-error "not been declared" }
+
+#pragma acc routine // { dg-error "not followed by function" }
+int i;
+
Index: libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c
===================================================================
--- libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c (revision 226952)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c (working copy)
@@ -23,7 +23,7 @@ main()
a = (int *)malloc (sizeof (int) * n);
-#pragma acc parallel copy (a[0:n]) vector_length (5) /* { dg-warning "using vector_length" } */
+#pragma acc parallel copy (a[0:n]) vector_length (32)
{
#pragma acc loop
for (i = 0; i < n; i++)
Index: libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c
===================================================================
--- libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c (revision 226952)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c (working copy)
@@ -25,7 +25,7 @@ main()
a = (int *)malloc (sizeof (int) * n);
-#pragma acc parallel copy (a[0:n]) vector_length (5) /* { dg-warning "using vector_length" } */
+#pragma acc parallel copy (a[0:n]) vector_length (32)
{
#pragma acc loop
for (i = 0; i < n; i++)