* [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684]
@ 2020-02-11 21:35 Marek Polacek
2020-02-12 0:30 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2020-02-11 21:35 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
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?
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
--
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684]
2020-02-11 21:35 [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684] Marek Polacek
@ 2020-02-12 0:30 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-02-12 0:30 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-12 0:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 21:35 [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684] Marek Polacek
2020-02-12 0:30 ` 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).