From b9424661f58de6c0aa9dc4c855c1fd913cc06282 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 14 Oct 2019 08:52:46 +0200 Subject: [PATCH] c-parser.c (c_parser_omp_all_clauses): Change bool NESTED_P argument into int NESTED... c/ * c-parser.c (c_parser_omp_all_clauses): Change bool NESTED_P argument into int NESTED, if it is 2, diagnose missing commas in between clauses. (c_parser_omp_context_selector): Pass 2 as last argument to c_parser_omp_all_clauses. cp/ * parser.c (cp_parser_omp_all_clauses): Change bool NESTED_P argument into int NESTED, if it is 2, diagnose missing commas in between clauses. (cp_parser_omp_context_selector): Pass 2 as last argument to cp_parser_omp_all_clauses. testsuite/ * c-c++-common/gomp/declare-variant-7.c: Add tests for clauses not separated by commas in simd selector trait properties. From-SVN: r276950 --- gcc/c/ChangeLog | 8 +++++++ gcc/c/c-parser.c | 24 ++++++++++++------- gcc/cp/ChangeLog | 8 +++++++ gcc/cp/parser.c | 24 ++++++++++++------- gcc/testsuite/ChangeLog | 5 ++++ .../c-c++-common/gomp/declare-variant-7.c | 6 ++++- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 5fb386c4b9e..c76baf060a7 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +2019-10-14 Jakub Jelinek + + * c-parser.c (c_parser_omp_all_clauses): Change bool NESTED_P argument + into int NESTED, if it is 2, diagnose missing commas in between + clauses. + (c_parser_omp_context_selector): Pass 2 as last argument to + c_parser_omp_all_clauses. + 2019-10-12 Jakub Jelinek * c-parser.c (c_parser_omp_context_selector): Improve error recovery. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 9d0b2b671f8..15095dd3214 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -15215,13 +15215,14 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, /* Parse all OpenMP clauses. The set clauses allowed by the directive is a bitmask in MASK. Return the list of clauses found. FINISH_P set if c_finish_omp_clauses should be called. - NESTED_P set if clauses should be terminated by closing paren instead - of end of pragma. */ + NESTED non-zero if clauses should be terminated by closing paren instead + of end of pragma. If it is 2, additionally commas are required in between + the clauses. */ static tree c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, const char *where, bool finish_p = true, - bool nested_p = false) + int nested = 0) { tree clauses = NULL; bool first = true; @@ -15233,11 +15234,18 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, const char *c_name; tree prev = clauses; - if (nested_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) + if (nested && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) break; - if (!first && c_parser_next_token_is (parser, CPP_COMMA)) - c_parser_consume_token (parser); + if (!first) + { + if (c_parser_next_token_is (parser, CPP_COMMA)) + c_parser_consume_token (parser); + else if (nested == 2) + error_at (c_parser_peek_token (parser)->location, + "clauses in % trait should be separated " + "by %<,%>"); + } here = c_parser_peek_token (parser)->location; c_kind = c_parser_omp_clause_name (parser); @@ -15520,7 +15528,7 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, } saw_error: - if (!nested_p) + if (!nested) c_parser_skip_to_pragma_eol (parser); if (finish_p) @@ -19279,7 +19287,7 @@ c_parser_omp_context_selector (c_parser *parser, tree set, tree parms) tree c; c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, - "simd", true, true); + "simd", true, 2); c = c_omp_declare_simd_clauses_to_numbers (parms == error_mark_node ? NULL_TREE : parms, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dcae4909d5e..af084974cf8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-10-14 Jakub Jelinek + + * parser.c (cp_parser_omp_all_clauses): Change bool NESTED_P argument + into int NESTED, if it is 2, diagnose missing commas in between + clauses. + (cp_parser_omp_context_selector): Pass 2 as last argument to + cp_parser_omp_all_clauses. + 2019-10-12 Jakub Jelinek * parser.c (cp_parser_omp_context_selector): Improve error recovery. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9bf690a0efb..53db8afc9f6 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -36078,13 +36078,14 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, /* Parse all OpenMP clauses. The set clauses allowed by the directive is a bitmask in MASK. Return the list of clauses found. FINISH_P set if finish_omp_clauses should be called. - NESTED_P set if clauses should be terminated by closing paren instead - of end of pragma. */ + NESTED non-zero if clauses should be terminated by closing paren instead + of end of pragma. If it is 2, additionally commas are required in between + the clauses. */ static tree cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, const char *where, cp_token *pragma_tok, - bool finish_p = true, bool nested_p = false) + bool finish_p = true, int nested = 0) { tree clauses = NULL; bool first = true; @@ -36099,11 +36100,18 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, const char *c_name; tree prev = clauses; - if (nested_p && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN)) + if (nested && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN)) break; - if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) - cp_lexer_consume_token (parser->lexer); + if (!first) + { + if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) + cp_lexer_consume_token (parser->lexer); + else if (nested == 2) + error_at (cp_lexer_peek_token (parser->lexer)->location, + "clauses in % trait should be separated " + "by %<,%>"); + } token = cp_lexer_peek_token (parser->lexer); c_kind = cp_parser_omp_clause_name (parser); @@ -36421,7 +36429,7 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, } } saw_error: - if (!nested_p) + if (!nested) cp_parser_skip_to_pragma_eol (parser, pragma_tok); if (finish_p) { @@ -40548,7 +40556,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p) properties = cp_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, - "simd", NULL, true, true); + "simd", NULL, true, 2); break; default: gcc_unreachable (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fbc3d27f7a3..5db77a788d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-14 Jakub Jelinek + + * c-c++-common/gomp/declare-variant-7.c: Add tests for clauses not + separated by commas in simd selector trait properties. + 2019-10-14 Aldy Hernandez * gcc.dg/tree-ssa/evrp4.c: Adjust for unsigned non-zero being diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c index f818cd5ec7b..1df63384dff 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c @@ -27,7 +27,11 @@ int f10 (float x, float y, float *q); int f11 (float x, float y, float *z); #pragma omp declare variant (f3) match (construct={simd(simdlen(4),inbranch,linear(y:1))}) int f12 (int x, int y); -#pragma omp declare variant (f3) match (construct={simd(inbranch,simdlen(5-1),linear(q:4-3))}) +#pragma omp declare variant (f3) match (construct={simd(inbranch, simdlen (5-1), linear (q:4-3))}) int f13 (int x, int q); #pragma omp declare variant (f3) match (construct={simd(inbranch,simdlen(4),linear(q:2))}) /* { dg-error "'f3' used as a variant with incompatible 'constructor' selector sets" "" { target c } } */ int f14 (int x, int q); +#pragma omp declare variant (f3) match (construct={simd(inbranch simdlen (4) linear (q:1))}) /* { dg-error "clauses in 'simd' trait should be separated by ','" } */ +int f15 (int x, int q); +#pragma omp declare variant (f3) match (construct={simd(inbranch, simdlen (5-1) linear (q:4-3))}) /* { dg-error "clauses in 'simd' trait should be separated by ','" } */ +int f16 (int x, int q); -- 2.30.2