From a04e69c0b12712bb90762dd20d7ffcd6f04e1da6 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 24 May 2016 16:00:39 +0200 Subject: [PATCH] Tighten syntax checking for OpenACC routine construct in C gcc/c/ * c-parser.c (c_parser_oacc_routine): Tighten syntax checks. gcc/testsuite/ * c-c++-common/goacc/routine-5.c: Add tests. * g++.dg/goacc/routine-2.C: Remove duplicate tests. * gfortran.dg/goacc/routine-6.f90: Add tests. From-SVN: r236639 --- gcc/c/ChangeLog | 4 ++++ gcc/c/c-parser.c | 19 ++++++++--------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/c-c++-common/goacc/routine-5.c | 21 +++++++++++++++---- gcc/testsuite/g++.dg/goacc/routine-2.C | 6 ------ gcc/testsuite/gfortran.dg/goacc/routine-6.f90 | 7 +++++++ 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9bb5ec1dfce..3d69cd57949 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2016-05-24 Thomas Schwinge + + * c-parser.c (c_parser_oacc_routine): Tighten syntax checks. + 2016-05-24 Richard Biener PR middle-end/70434 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index c2c83143c05..1bc5eed7f55 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -13983,25 +13983,24 @@ c_parser_oacc_routine (c_parser *parser, enum pragma_context context) c_parser_consume_token (parser); c_token *token = c_parser_peek_token (parser); - if (token->type == CPP_NAME && (token->id_kind == C_ID_ID || token->id_kind == C_ID_TYPENAME)) { decl = lookup_name (token->value); if (!decl) - { - error_at (token->location, "%qE has not been declared", - token->value); - decl = error_mark_node; - } + error_at (token->location, "%qE has not been declared", + token->value); + c_parser_consume_token (parser); } else c_parser_error (parser, "expected function name"); - if (token->type != CPP_CLOSE_PAREN) - c_parser_consume_token (parser); - - c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); + if (!decl + || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) + { + c_parser_skip_to_pragma_eol (parser, false); + return; + } } /* Build a chain of clauses. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 586202e9fa0..361fbbdedba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-05-24 Thomas Schwinge + + * c-c++-common/goacc/routine-5.c: Add tests. + * g++.dg/goacc/routine-2.C: Remove duplicate tests. + * gfortran.dg/goacc/routine-6.f90: Add tests. + 2016-05-24 Richard Biener PR tree-optimization/71253 diff --git a/gcc/testsuite/c-c++-common/goacc/routine-5.c b/gcc/testsuite/c-c++-common/goacc/routine-5.c index 2a9db90dcb9..1efd154f8e6 100644 --- a/gcc/testsuite/c-c++-common/goacc/routine-5.c +++ b/gcc/testsuite/c-c++-common/goacc/routine-5.c @@ -38,13 +38,26 @@ namespace g {} #pragma acc routine /* { dg-error "not followed by" "" { target c++ } } */ using namespace g; -#pragma acc routine (g) /* { dg-error "does not refer to" "" { target c++ } } */ +#pragma acc routine (g) /* { dg-error "does not refer to a function" "" { target c++ } } */ -#endif +#endif /* __cplusplus */ -#pragma acc routine (a) /* { dg-error "does not refer to" } */ +#pragma acc routine (a) /* { dg-error "does not refer to a function" } */ -#pragma acc routine (c) /* { dg-error "does not refer to" } */ +#pragma acc routine (c) /* { dg-error "does not refer to a function" } */ + + +#pragma acc routine () vector /* { dg-error "expected (function name|unqualified-id) before .\\). token" } */ + +#pragma acc routine (+) /* { dg-error "expected (function name|unqualified-id) before .\\+. token" } */ + + +extern void R1(void); +extern void R2(void); +#pragma acc routine (R1, R2, R3) worker /* { dg-error "expected .\\). before .,. token" } */ +#pragma acc routine (R1 R2 R3) worker /* { dg-error "expected .\\). before .R2." } */ +#pragma acc routine (R1) worker +#pragma acc routine (R2) worker void Bar (); diff --git a/gcc/testsuite/g++.dg/goacc/routine-2.C b/gcc/testsuite/g++.dg/goacc/routine-2.C index 2d1646647af..ea7c9bf7393 100644 --- a/gcc/testsuite/g++.dg/goacc/routine-2.C +++ b/gcc/testsuite/g++.dg/goacc/routine-2.C @@ -14,15 +14,9 @@ one() int incr (int); float incr (float); -int inc; #pragma acc routine (incr) /* { dg-error "names a set of overloads" } */ -#pragma acc routine (increment) /* { dg-error "has not been declared" } */ - -#pragma acc routine (inc) /* { dg-error "does not refer to a function" } */ - -#pragma acc routine (+) /* { dg-error "expected unqualified-id before '.' token" } */ int sum (int, int); diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-6.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-6.f90 index 10951ee686e..10943cff304 100644 --- a/gcc/testsuite/gfortran.dg/goacc/routine-6.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/routine-6.f90 @@ -29,6 +29,13 @@ program main !$acc routine (subr1) ! { dg-error "invalid function name" } external :: subr2 !$acc routine (subr2) + + external :: R1, R2 + !$acc routine (R1 R2 R3) ! { dg-error "Syntax error in \\!\\\$ACC ROUTINE \\( NAME \\) at \\(1\\), expecting .\\). after NAME" } + !$acc routine (R1, R2, R3) ! { dg-error "Syntax error in \\!\\\$ACC ROUTINE \\( NAME \\) at \\(1\\), expecting .\\). after NAME" } + !$acc routine (R1) + !$acc routine (R2) + !$acc parallel !$acc loop do i = 1, n -- 2.30.2