From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684]
Date: Wed, 12 Feb 2020 00:30:00 -0000 [thread overview]
Message-ID: <2eb6a8d4-4465-6b6c-318a-ac1e14ba1c14@redhat.com> (raw)
In-Reply-To: <20200211213522.392020-1-polacek@redhat.com>
On 2/11/20 10:35 PM, Marek Polacek wrote:
> We crash when parsing
>
> [[a::
>
> because we see a CPP_SCOPE and then we're trying to consume a CPP_EOF
> token. So peek before consuming it.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
OK.
> PR c++/93684 - ICE-on-invalid with broken attribute.
> * parser.c (cp_parser_std_attribute): Peek a token first before
> consuming it.
>
> * g++.dg/parse/attr4.C: New test.
> ---
> gcc/cp/parser.c | 3 ++-
> gcc/testsuite/g++.dg/parse/attr4.C | 3 +++
> 2 files changed, 5 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/parse/attr4.C
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 640affd8368..e8a536ae22f 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -26720,7 +26720,7 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
> "with scoped attribute token");
> attr_ns = attr_id;
>
> - token = cp_lexer_consume_token (parser->lexer);
> + token = cp_lexer_peek_token (parser->lexer);
> if (token->type == CPP_NAME)
> attr_id = token->u.value;
> else if (token->type == CPP_KEYWORD)
> @@ -26733,6 +26733,7 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
> "expected an identifier for the attribute name");
> return error_mark_node;
> }
> + cp_lexer_consume_token (parser->lexer);
>
> attr_ns = canonicalize_attr_name (attr_ns);
> attr_id = canonicalize_attr_name (attr_id);
> diff --git a/gcc/testsuite/g++.dg/parse/attr4.C b/gcc/testsuite/g++.dg/parse/attr4.C
> new file mode 100644
> index 00000000000..7713fc96c64
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/attr4.C
> @@ -0,0 +1,3 @@
> +// PR c++/93684 - ICE-on-invalid with broken attribute.
> +
> +[[a:: // { dg-error "expected|expected" }
>
> base-commit: ad21e0072e20b7c8e4d7af5ca78f24cc6ae407d1
>
prev parent reply other threads:[~2020-02-12 0:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 21:35 Marek Polacek
2020-02-12 0:30 ` Jason Merrill [this message]
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=2eb6a8d4-4465-6b6c-318a-ac1e14ba1c14@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@redhat.com \
/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).