* [C++ PATCH] Fix C++ parser endless diagnostics on CPP_PRAGMA_EOL (PR c++/88258)
@ 2018-11-30 20:54 Jakub Jelinek
2018-12-02 0:08 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-11-30 20:54 UTC (permalink / raw)
To: Jason Merrill, Nathan Sidwell; +Cc: gcc-patches
Hi!
The following testcase endlessly diagnoses a syntax error.
The problem is that the various C++ parser routines to skip tokens until
something happily skip over CPP_PRAGMA that starts a pragma line, but
always stop at CPP_PRAGMA_EOL, but the caller expect them to stop at
something different.
The fix is similar to what the C FE already does, treat CPP_PRAGMA_EOL
as CPP_EOF only if in_pragma flag is set. Otherwise we didn't really parse
CPP_PRAGMA normally and should skip everything until we find whatever we are
looking for.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2018-11-30 Jakub Jelinek <jakub@redhat.com>
PR c++/88258
* parser.c (cp_parser_skip_to_closing_parenthesis_1,
cp_parser_skip_to_end_of_statement,
cp_parser_skip_to_end_of_block_or_statement,
cp_parser_skip_to_closing_brace,
cp_parser_skip_to_closing_square_bracket,
cp_parser_skip_balanced_tokens): Don't treat CPP_PRAGMA_EOL specially
if in_pragma is false.
* g++.dg/gomp/pr88258.C: New test.
--- gcc/cp/parser.c.jj 2018-11-29 08:41:30.804788606 +0100
+++ gcc/cp/parser.c 2018-11-30 14:18:51.928839749 +0100
@@ -3556,8 +3556,11 @@ cp_parser_skip_to_closing_parenthesis_1
switch (token->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* If we've run out of tokens, then there is no closing `)'. */
return 0;
@@ -3652,8 +3655,11 @@ cp_parser_skip_to_end_of_statement (cp_p
switch (token->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* If we've run out of tokens, stop. */
return;
@@ -3742,8 +3748,11 @@ cp_parser_skip_to_end_of_block_or_statem
switch (token->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* If we've run out of tokens, stop. */
return;
@@ -3792,8 +3801,11 @@ cp_parser_skip_to_closing_brace (cp_pars
switch (token->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* If we've run out of tokens, stop. */
return false;
@@ -22498,8 +22510,11 @@ cp_parser_skip_to_closing_square_bracket
switch (token->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* If we've run out of tokens, then there is no closing `]'. */
return false;
@@ -26008,8 +26023,11 @@ cp_parser_skip_balanced_tokens (cp_parse
do
switch (cp_lexer_peek_nth_token (parser->lexer, n++)->type)
{
- case CPP_EOF:
case CPP_PRAGMA_EOL:
+ if (!parser->lexer->in_pragma)
+ break;
+ /* FALLTHRU */
+ case CPP_EOF:
/* Ran out of tokens. */
return orig_n;
case CPP_OPEN_PAREN:
--- gcc/testsuite/g++.dg/gomp/pr88258.C.jj 2018-11-30 14:26:00.806805739 +0100
+++ gcc/testsuite/g++.dg/gomp/pr88258.C 2018-11-30 14:25:33.614251741 +0100
@@ -0,0 +1,11 @@
+// PR c++/88258
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+void
+foo (bar int p) // { dg-error "variable or field|was not declared in this scope" }
+{
+ int i, x;
+ #pragma omp atomic write
+ x = 6;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Fix C++ parser endless diagnostics on CPP_PRAGMA_EOL (PR c++/88258)
2018-11-30 20:54 [C++ PATCH] Fix C++ parser endless diagnostics on CPP_PRAGMA_EOL (PR c++/88258) Jakub Jelinek
@ 2018-12-02 0:08 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-12-02 0:08 UTC (permalink / raw)
To: Jakub Jelinek, Nathan Sidwell; +Cc: gcc-patches
On 11/30/18 3:54 PM, Jakub Jelinek wrote:
> Hi!
>
> The following testcase endlessly diagnoses a syntax error.
> The problem is that the various C++ parser routines to skip tokens until
> something happily skip over CPP_PRAGMA that starts a pragma line, but
> always stop at CPP_PRAGMA_EOL, but the caller expect them to stop at
> something different.
>
> The fix is similar to what the C FE already does, treat CPP_PRAGMA_EOL
> as CPP_EOF only if in_pragma flag is set. Otherwise we didn't really parse
> CPP_PRAGMA normally and should skip everything until we find whatever we are
> looking for.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-02 0:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30 20:54 [C++ PATCH] Fix C++ parser endless diagnostics on CPP_PRAGMA_EOL (PR c++/88258) Jakub Jelinek
2018-12-02 0:08 ` Jason Merrill
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).