From e428a9cf85a8bdde9d031a215e10bd96eb3b789a Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 11 Feb 2020 15:29:24 -0500 Subject: [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684] 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. 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/ChangeLog | 6 ++++++ gcc/cp/parser.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/attr4.C | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/attr4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7567bbe6722..c578cdbfe33 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-02-12 Marek Polacek + + PR c++/93684 - ICE-on-invalid with broken attribute. + * parser.c (cp_parser_std_attribute): Peek a token first before + consuming it. + 2020-02-11 Jason Merrill PR c++/93675 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/ChangeLog b/gcc/testsuite/ChangeLog index 433b0af7874..968b903411d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-12 Marek Polacek + + PR c++/93684 - ICE-on-invalid with broken attribute. + * g++.dg/parse/attr4.C: New test. + 2020-02-12 Jakub Jelinek PR target/93670 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" } -- 2.30.2