public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3016] openmp: Fix ICE on requires clause with atomic_default_mem_order (
Date: Thu, 19 Aug 2021 08:43:34 +0000 (GMT)	[thread overview]
Message-ID: <20210819084334.461713858403@sourceware.org> (raw)

https://gcc.gnu.org/g:c04d766942274da89b236c4cb7e954b26da397c7

commit r12-3016-gc04d766942274da89b236c4cb7e954b26da397c7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Aug 19 10:38:19 2021 +0200

    openmp: Fix ICE on requires clause with atomic_default_mem_order (
    
    When working on error directive, I've noticed the C FE ICEs on
      #pragma omp requires atomic_default_mem_order (
    where it tries to peek 2nd token after the CPP_PRAGMA_EOL (or CPP_EOF)
    in there in order to improve error-recovery on say
    atomic_default_mem_order (acquire)
    or
    atomic_default_mem_order (seqcst)
    etc.  The C++ FE didn't ICE, but it is better to follow the same thing there.
    
    2021-08-19  Jakub Jelinek  <jakub@redhat.com>
    
    gcc/c/
            * c-parser.c (c_parser_omp_requires): Don't call
            c_parser_peek_2nd_token and optionally consume token if current
            token is CPP_EOF, CPP_PRAGMA_EOL or CPP_CLOSE_PAREN.
    gcc/cp/
            * parser.c (cp_parser_omp_requires): Don't call cp_lexer_nth_token_is
            and optionally consume token if current token is CPP_EOF,
            CPP_PRAGMA_EOL or CPP_CLOSE_PAREN.
    gcc/testsuite/
            * c-c++-common/gomp/requires-3.c: Add testcase for
            atomic_default_mem_order ( at the end of line without corresponding ).

Diff:
---
 gcc/c/c-parser.c                             | 15 ++++++++++++---
 gcc/cp/parser.c                              | 15 ++++++++++++---
 gcc/testsuite/c-c++-common/gomp/requires-3.c |  2 ++
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index d5f51b11423..407f279fc03 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -21710,9 +21710,18 @@ c_parser_omp_requires (c_parser *parser)
 		      error_at (c_parser_peek_token (parser)->location,
 				"expected %<seq_cst%>, %<relaxed%> or "
 				"%<acq_rel%>");
-		      if (c_parser_peek_2nd_token (parser)->type
-			  == CPP_CLOSE_PAREN)
-			c_parser_consume_token (parser);
+		      switch (c_parser_peek_token (parser)->type)
+			{
+			case CPP_EOF:
+			case CPP_PRAGMA_EOL:
+			case CPP_CLOSE_PAREN:
+			  break;
+			default:
+			  if (c_parser_peek_2nd_token (parser)->type
+			      == CPP_CLOSE_PAREN)
+			    c_parser_consume_token (parser);
+			  break;
+			}
 		    }
 		  else
 		    c_parser_consume_token (parser);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 1d48b8333fe..0af1a2ccfbc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -45479,9 +45479,18 @@ cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok)
 		      error_at (cp_lexer_peek_token (parser->lexer)->location,
 				"expected %<seq_cst%>, %<relaxed%> or "
 				"%<acq_rel%>");
-		      if (cp_lexer_nth_token_is (parser->lexer, 2,
-						 CPP_CLOSE_PAREN))
-			cp_lexer_consume_token (parser->lexer);
+		      switch (cp_lexer_peek_token (parser->lexer)->type)
+			{
+			case CPP_EOF:
+			case CPP_PRAGMA_EOL:
+			case CPP_CLOSE_PAREN:
+			  break;
+			default:
+			  if (cp_lexer_nth_token_is (parser->lexer, 2,
+						     CPP_CLOSE_PAREN))
+			    cp_lexer_consume_token (parser->lexer);
+			  break;
+			}
 		    }
 		  else
 		    cp_lexer_consume_token (parser->lexer);
diff --git a/gcc/testsuite/c-c++-common/gomp/requires-3.c b/gcc/testsuite/c-c++-common/gomp/requires-3.c
index e5a6cbbdd2a..0e55b666ebf 100644
--- a/gcc/testsuite/c-c++-common/gomp/requires-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/requires-3.c
@@ -1,3 +1,5 @@
 #pragma omp requires atomic_default_mem_order(acquire)	/* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
 #pragma omp requires atomic_default_mem_order(release)	/* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
 #pragma omp requires atomic_default_mem_order(foobar)	/* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
+#pragma omp requires atomic_default_mem_order (	/* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
+/* { dg-error "expected '\\\)' before end of line" "" { target *-*-* } .-1 } */


                 reply	other threads:[~2021-08-19  8:43 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=20210819084334.461713858403@sourceware.org \
    --to=jakub@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).