Hi!

I've noticed that we allow a trailing comma on OpenMP atomic construct
if there is at least one clause.  Commas should be only allowed to
separate the clauses (or in OpenMP 5.1 to separate directive name
from the clauses).

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

Strangely, both clang and ICC suffer from the same bug.

2021-07-02  Jakub Jelinek  <ja...@redhat.com>

        PR c/101297
        * c-parser.c (c_parser_omp_atomic): Consume comma only if it
        appears before a CPP_NAME.

        * parser.c (cp_parser_omp_atomic): Consume comma only if it
        appears before a CPP_NAME.

        * c-c++-common/gomp/atomic-24.c: New test.

--- gcc/c/c-parser.c.jj 2021-06-25 10:36:22.076021228 +0200
+++ gcc/c/c-parser.c    2021-07-02 14:15:55.242100829 +0200
@@ -17533,7 +17533,9 @@ c_parser_omp_atomic (location_t loc, c_p
 
   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;
--- gcc/cp/parser.c.jj  2021-07-01 22:29:16.856489440 +0200
+++ gcc/cp/parser.c     2021-07-02 14:16:55.879240595 +0200
@@ -39171,7 +39171,9 @@ cp_parser_omp_atomic (cp_parser *parser,
 
   while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
     {
-      if (!first && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+      if (!first
+         && cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
+         && cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME))
        cp_lexer_consume_token (parser->lexer);
 
       first = false;
--- gcc/testsuite/c-c++-common/gomp/atomic-24.c.jj      2021-07-02 
14:23:41.375487969 +0200
+++ gcc/testsuite/c-c++-common/gomp/atomic-24.c 2021-07-02 14:23:34.268588790 
+0200
@@ -0,0 +1,12 @@
+/* PR c/101297 */
+
+int i;
+
+void
+foo (void)
+{
+  #pragma omp atomic update,   /* { dg-error "expected end of line before ',' 
token" } */
+  i++;
+  #pragma omp atomic update,,  /* { dg-error "expected end of line before ',' 
token" } */
+  i++;
+}

        Jakub

Reply via email to