aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-03-15 09:15:27 +0100
committerJakub Jelinek <jakub@redhat.com>2022-03-15 09:15:27 +0100
commitefd1582926f3278a5e57ebab7d87fc870f06ecea (patch)
treea806957e5961f4f7f3f12e77338abf217b3e4ba4
parenta2645cd8fb33b36d737b310e26f4c47401305c7b (diff)
downloadgcc-efd1582926f3278a5e57ebab7d87fc870f06ecea.zip
gcc-efd1582926f3278a5e57ebab7d87fc870f06ecea.tar.gz
gcc-efd1582926f3278a5e57ebab7d87fc870f06ecea.tar.bz2
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.
-rw-r--r--gcc/cp/parser.cc2
-rw-r--r--gcc/testsuite/g++.dg/gomp/pr104623.C9
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 87b9781..15ad640 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 0000000..725e19e
--- /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
+}