]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Reject #pragma omp atomic update, [PR101297]
authorJakub Jelinek <jakub@redhat.com>
Fri, 2 Jul 2021 19:57:24 +0000 (21:57 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 2 Jul 2021 19:57:24 +0000 (21:57 +0200)
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).

2021-07-02  Jakub Jelinek  <jakub@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
gcc/cp/parser.c
gcc/testsuite/c-c++-common/gomp/atomic-24.c [new file with mode: 0644]

index 3922b569c3a69444050dcc060fdb3dca33aa16a7..9a56e0c04c6a9b6ef1db0a61cfc94d928d140011 100644 (file)
@@ -17533,7 +17533,9 @@ c_parser_omp_atomic (location_t loc, c_parser *parser, bool openacc)
 
   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;
index 02daa7a6f6a2442e5ff2c604a5d8f716bddf881b..3550cd06dc19424ab69389bf1f26652d189d08fb 100644 (file)
@@ -39171,7 +39171,9 @@ cp_parser_omp_atomic (cp_parser *parser, cp_token *pragma_tok, bool openacc)
 
   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;
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-24.c b/gcc/testsuite/c-c++-common/gomp/atomic-24.c
new file mode 100644 (file)
index 0000000..f70c805
--- /dev/null
@@ -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++;
+}