public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7652] c++: Fix up cp_parser_skip_to_pragma_eol [PR104623]
@ 2022-03-15  8:15 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-03-15  8:15 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-7652-gefd1582926f3278a5e57ebab7d87fc870f06ecea
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 15 09:15:27 2022 +0100

    c++: Fix up cp_parser_skip_to_pragma_eol [PR104623]
    
    We ICE on the following testcase, because we tentatively parse it multiple
    times and the erroneous attribute syntax results in
    cp_parser_skip_to_end_of_statement, which when seeing CPP_PRAGMA (can be
    any deferred one, OpenMP/OpenACC/ivdep etc.) it calls
    cp_parser_skip_to_pragma_eol, which calls cp_lexer_purge_tokens_after.
    That call purges all the tokens from CPP_PRAGMA until CPP_PRAGMA_EOL,
    excluding the initial CPP_PRAGMA though (but including the final
    CPP_PRAGMA_EOL).  This means the second time we parse this, we see
    CPP_PRAGMA with no tokens after it from the pragma, most importantly
    not the CPP_PRAGMA_EOL, so either if it is the last pragma in the TU,
    we ICE, or if there are other pragmas we treat everything in between
    as a pragma.
    
    I've tried various things, including making the CPP_PRAGMA token
    itself also purged, or changing the cp_parser_skip_to_end_of_statement
    (and cp_parser_skip_to_end_of_block_or_statement) to call it with
    NULL instead of token, so that this purging isn't done there,
    but each patch resulted in lots of regressions.
    But removing the purging altogether surprisingly doesn't regress anything,
    and I think it is the right thing, if we e.g. parse tentatively, why can't
    we parse the pragma multiple times or at least skip over it?
    
    2022-03-15  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/104623
            * parser.cc (cp_parser_skip_to_pragma_eol): Don't purge any tokens.
    
            * g++.dg/gomp/pr104623.C: New test.

Diff:
---
 gcc/cp/parser.cc                     | 2 --
 gcc/testsuite/g++.dg/gomp/pr104623.C | 9 +++++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 87b9781e793..15ad6400730 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -4111,8 +4111,6 @@ cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok)
 
   if (pragma_tok)
     {
-      /* Ensure that the pragma is not parsed again.  */
-      cp_lexer_purge_tokens_after (parser->lexer, pragma_tok);
       parser->lexer->in_pragma = false;
       if (parser->lexer->in_omp_attribute_pragma
 	  && cp_lexer_next_token_is (parser->lexer, CPP_EOF))
diff --git a/gcc/testsuite/g++.dg/gomp/pr104623.C b/gcc/testsuite/g++.dg/gomp/pr104623.C
new file mode 100644
index 00000000000..725e19e8c26
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr104623.C
@@ -0,0 +1,9 @@
+// PR c++/104623
+// { dg-do compile }
+
+void
+foo ()
+{
+  struct __attribute__() a	// { dg-error "expected primary-expression before" }
+  #pragma omp task
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-15  8:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15  8:15 [gcc r12-7652] c++: Fix up cp_parser_skip_to_pragma_eol [PR104623] Jakub Jelinek

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).