From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 151543858D39; Fri, 29 Jul 2022 08:00:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 151543858D39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1888] openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 97d32048c04e9787fccadc4bae1c042754503e34 X-Git-Newrev: 2dcceedb3c121f2498ae58d8414e7b8454b7bf55 Message-Id: <20220729080053.151543858D39@sourceware.org> Date: Fri, 29 Jul 2022 08:00:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2022 08:00:53 -0000 https://gcc.gnu.org/g:2dcceedb3c121f2498ae58d8414e7b8454b7bf55 commit r13-1888-g2dcceedb3c121f2498ae58d8414e7b8454b7bf55 Author: Jakub Jelinek Date: Fri Jul 29 09:59:19 2022 +0200 openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448] 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 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. Diff: --- gcc/cp/parser.cc | 4 +++- gcc/testsuite/c-c++-common/gomp/atomic-32.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 4f67441eeb1..826595a3722 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -41535,7 +41535,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); 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 index 00000000000..e39a96789d6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/atomic-32.c @@ -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)" } */ +}