From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Tobias Burnus <tobias@codesourcery.com>
Subject: [committed] openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448]
Date: Fri, 29 Jul 2022 10:04:57 +0200 [thread overview]
Message-ID: <YuOUqc5uoN4S8/to@tucnak> (raw)
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
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.
--- gcc/cp/parser.cc.jj 2022-07-26 10:32:23.557273390 +0200
+++ gcc/cp/parser.cc 2022-07-28 15:12:44.288195066 +0200
@@ -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);
--- gcc/testsuite/c-c++-common/gomp/atomic-32.c.jj 2022-07-28 15:23:54.567237524 +0200
+++ gcc/testsuite/c-c++-common/gomp/atomic-32.c 2022-07-28 15:25:25.127027325 +0200
@@ -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)" } */
+}
Jakub
reply other threads:[~2022-07-29 8:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YuOUqc5uoN4S8/to@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).