diff mbox series

c++: Fix ICE-on-invalid with broken attribute [PR93684]

Message ID 20200211213522.392020-1-polacek@redhat.com
State New
Headers show
Series c++: Fix ICE-on-invalid with broken attribute [PR93684] | expand

Commit Message

Marek Polacek Feb. 11, 2020, 9:35 p.m. UTC
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


base-commit: ad21e0072e20b7c8e4d7af5ca78f24cc6ae407d1

Comments

Jason Merrill Feb. 12, 2020, 12:29 a.m. UTC | #1
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
>
diff mbox series

Patch

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" }