public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3039] openmp: Diagnose some superfluous commas in OpenMP parsing
@ 2021-08-20 9:31 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-08-20 9:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f9400e4e4705845f2b0cdc4eab30c214e0e4cbe0
commit r12-3039-gf9400e4e4705845f2b0cdc4eab30c214e0e4cbe0
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Aug 20 11:29:48 2021 +0200
openmp: Diagnose some superfluous commas in OpenMP parsing
While working on error directive, I've noticed a few spots in OpenMP
parsing where we consume and don't diagnose superfluous commas at the end
(either of depend sink arguments or at the end of requires pragma).
2021-08-20 Jakub Jelinek <jakub@redhat.com>
gcc/c/
* c-parser.c (c_parser_omp_clause_depend_sink): Reject spurious
comma at the end of list.
(c_parser_omp_requires): Likewise.
gcc/cp/
* parser.c (cp_parser_omp_clause_depend_sink): Reject spurious
comma at the end of list. Don't parse closing paren here...
(cp_parser_omp_clause_depend): ... but here instead.
gcc/testsuite/
* c-c++-common/gomp/sink-5.c: New test.
* c-c++-common/gomp/requires-3.c: Add test for spurious comma
at the end of pragma line.
Diff:
---
gcc/c/c-parser.c | 8 ++++++--
gcc/cp/parser.c | 13 ++++++++++---
gcc/testsuite/c-c++-common/gomp/requires-3.c | 1 +
gcc/testsuite/c-c++-common/gomp/sink-5.c | 16 ++++++++++++++++
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 407f279fc03..ab79e9c0ea8 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -15481,7 +15481,9 @@ c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc,
OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
}
- if (c_parser_next_token_is_not (parser, CPP_COMMA))
+ if (c_parser_next_token_is_not (parser, CPP_COMMA)
+ || c_parser_peek_2nd_token (parser)->type != CPP_NAME
+ || c_parser_peek_2nd_token (parser)->id_kind != C_ID_ID)
break;
c_parser_consume_token (parser);
@@ -21663,7 +21665,9 @@ c_parser_omp_requires (c_parser *parser)
location_t loc = c_parser_peek_token (parser)->location;
while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL))
{
- if (!first && c_parser_next_token_is (parser, CPP_COMMA))
+ if (!first
+ && c_parser_next_token_is (parser, CPP_COMMA)
+ && c_parser_peek_2nd_token (parser)->type == CPP_NAME)
c_parser_consume_token (parser);
first = false;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0af1a2ccfbc..d321364220c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -38465,13 +38465,14 @@ cp_parser_omp_clause_depend_sink (cp_parser *parser, location_t clause_loc,
OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1;
}
- if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
+ if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA)
+ || !cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME))
break;
cp_lexer_consume_token (parser->lexer);
}
- if (cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN) && vec)
+ if (vec)
{
tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND);
OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK;
@@ -38791,7 +38792,13 @@ cp_parser_omp_clause_depend (cp_parser *parser, tree list, location_t loc)
goto resync_fail;
if (kind == OMP_CLAUSE_DEPEND_SINK)
- nlist = cp_parser_omp_clause_depend_sink (parser, loc, list);
+ {
+ nlist = cp_parser_omp_clause_depend_sink (parser, loc, list);
+ if (!parens.require_close (parser))
+ cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
+ /*or_comma=*/false,
+ /*consume_paren=*/true);
+ }
else
{
nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_DEPEND,
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-3.c b/gcc/testsuite/c-c++-common/gomp/requires-3.c
index 0e55b666ebf..bd2479ba8ff 100644
--- a/gcc/testsuite/c-c++-common/gomp/requires-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/requires-3.c
@@ -3,3 +3,4 @@
#pragma omp requires atomic_default_mem_order(foobar) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
#pragma omp requires atomic_default_mem_order ( /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
/* { dg-error "expected '\\\)' before end of line" "" { target *-*-* } .-1 } */
+#pragma omp requires atomic_default_mem_order(seq_cst), /* { dg-error "expected end of line before ',' token" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/sink-5.c b/gcc/testsuite/c-c++-common/gomp/sink-5.c
new file mode 100644
index 00000000000..4fbaa8a03cb
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/sink-5.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+void bar (int);
+
+void
+foo ()
+{
+ int i;
+#pragma omp parallel for ordered(1)
+ for (i = 0; i < 100; ++i)
+ {
+#pragma omp ordered depend(sink:i-1,) /* { dg-error "expected '\\\)' before ',' token" } */
+ bar (i);
+#pragma omp ordered depend(source)
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-20 9:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 9:31 [gcc r12-3039] openmp: Diagnose some superfluous commas in OpenMP parsing Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).