public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tobias Burnus <burnus@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-12] openmp: Reject invalid forms of C++ #pragma omp atomic compare [PR106448]
Date: Fri, 29 Jul 2022 09:16:55 +0000 (GMT)	[thread overview]
Message-ID: <20220729091655.03DD73858429@sourceware.org> (raw)

https://gcc.gnu.org/g:70d8133b609acdf23bdec3d7adf9c437605795e5

commit 70d8133b609acdf23bdec3d7adf9c437605795e5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 29 11:12:03 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  <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)

Diff:
---
 gcc/cp/ChangeLog.omp                        | 10 ++++++++++
 gcc/cp/parser.cc                            |  4 +++-
 gcc/testsuite/ChangeLog.omp                 |  8 ++++++++
 gcc/testsuite/c-c++-common/gomp/atomic-32.c | 14 ++++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index b856f4ae0d4..d107e6cd9e6 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -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:
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 44643cd4a09..2fd1d2b78c3 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -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);
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 2567e10231f..89b5283cdba 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -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
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)" } */
+}


                 reply	other threads:[~2022-07-29  9:16 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=20220729091655.03DD73858429@sourceware.org \
    --to=burnus@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).