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  <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.
This commit is contained in:
Jakub Jelinek 2022-07-29 09:59:19 +02:00
parent 97d32048c0
commit 2dcceedb3c
2 changed files with 17 additions and 1 deletions

View file

@ -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);

View file

@ -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)" } */
}