]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448]
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Jul 2022 09:12:03 +0000 (11:12 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 29 Jul 2022 09:12:03 +0000 (11:12 +0200)
The allowed syntaxes of atomic compare don't allow ()s around the condition
of ?:, but we were accepting it in one case for C++.

Fixed thusly.

2022-07-29  Jakub Jelinek  <jakub@redhat.com>

PR c++/106448
* parser.cc (cp_parser_omp_atomic): For simple cast followed by
CPP_QUERY token, don't try cp_parser_binary_operation if compare
is true.

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

(cherry picked from commit 2dcceedb3c121f2498ae58d8414e7b8454b7bf55)

gcc/cp/ChangeLog.omp
gcc/cp/parser.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/atomic-32.c [new file with mode: 0644]

index b856f4ae0d4c269059e2a00e2c1c3c1c042ba855..d107e6cd9e643dc76d38bd85cb6c66d72ab14248 100644 (file)
@@ -1,3 +1,13 @@
+2022-07-29  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/106448
+       * parser.cc (cp_parser_omp_atomic): For simple cast followed by
+       CPP_QUERY token, don't try cp_parser_binary_operation if compare
+       is true.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 44643cd4a0968003a361c4f4385658656ed1ac5f..2fd1d2b78c3b30cbf0cd8fcae5c61b2e74db8499 100644 (file)
@@ -41554,7 +41554,9 @@ restart:
              goto saw_error;
            }
          token = cp_lexer_peek_token (parser->lexer);
-         if (token->type != CPP_SEMICOLON && !cp_tree_equal (lhs, rhs1))
+         if (token->type != CPP_SEMICOLON
+             && (!compare || token->type != CPP_QUERY)
+             && !cp_tree_equal (lhs, rhs1))
            {
              cp_parser_abort_tentative_parse (parser);
              cp_parser_parse_tentatively (parser);
index 2567e10231f2ce1ef70f20d8dbe462b06865c801..89b5283cdbaa9b72cf9ba8ae14e4280aad4f431b 100644 (file)
@@ -1,3 +1,11 @@
+2022-07-29  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/106448
+       * c-c++-common/gomp/atomic-32.c: New test.
+
 2022-07-12  Andrew Stubbs  <ams@codesourcery.com>
 
        * lib/target-supports.exp
diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-32.c b/gcc/testsuite/c-c++-common/gomp/atomic-32.c
new file mode 100644 (file)
index 0000000..e39a967
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c++/106448 */
+
+int x, expr;
+  
+void
+foo (void)
+{
+  #pragma omp atomic compare
+  x = (expr > x) ? expr : x;   /* { dg-error "invalid (form|operator)" } */
+  #pragma omp atomic compare
+  x = (x < expr) ? expr : x;   /* { dg-error "invalid (form|operator)" } */
+  #pragma omp atomic compare
+  x = (x == expr) ? expr : x;  /* { dg-error "invalid (form|operator)" } */
+}