public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
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 attributes [PR96637]
Date: Tue, 24 May 2022 08:22:22 -0400	[thread overview]
Message-ID: <e310ca51-f355-3799-617b-239536f3ef87@redhat.com> (raw)
In-Reply-To: <20220429141233.41897-1-polacek@redhat.com>

On 4/29/22 10:12, Marek Polacek wrote:
> This patch fixes crashes with invalid attributes.  Arguably it could
> make sense to assert seen_error() too.

So in this testcase we have TREE_CHAIN of a TREE_LIST pointing to 
error_mark_node?  Can we avoid that?

> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk = GCC 13?
> 
> 	PR c++/96637
> 
> gcc/ChangeLog:
> 
> 	* attribs.cc (decl_attributes): Check error_mark_node.
> 
> gcc/cp/ChangeLog:
> 
> 	* decl2.cc (cp_check_const_attributes): Check error_mark_node.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/parse/error64.C: New test.
> ---
>   gcc/attribs.cc                       | 3 +++
>   gcc/cp/decl2.cc                      | 2 ++
>   gcc/testsuite/g++.dg/parse/error64.C | 4 ++++
>   3 files changed, 9 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/parse/error64.C
> 
> diff --git a/gcc/attribs.cc b/gcc/attribs.cc
> index b219f878042..ff157dcf81c 100644
> --- a/gcc/attribs.cc
> +++ b/gcc/attribs.cc
> @@ -700,6 +700,9 @@ decl_attributes (tree *node, tree attributes, int flags,
>        in the same order as in the source.  */
>     for (tree attr = attributes; attr; attr = TREE_CHAIN (attr))
>       {
> +      if (attr == error_mark_node)
> +	continue;
> +
>         tree ns = get_attribute_namespace (attr);
>         tree name = get_attribute_name (attr);
>         tree args = TREE_VALUE (attr);
> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> index d2b29208ed5..c3ff1962a75 100644
> --- a/gcc/cp/decl2.cc
> +++ b/gcc/cp/decl2.cc
> @@ -1537,6 +1537,8 @@ cp_check_const_attributes (tree attributes)
>         /* As we implement alignas using gnu::aligned attribute and
>   	 alignas argument is a constant expression, force manifestly
>   	 constant evaluation of aligned attribute argument.  */
> +      if (attr == error_mark_node)
> +	continue;
>         bool manifestly_const_eval
>   	= is_attribute_p ("aligned", get_attribute_name (attr));
>         for (arg = TREE_VALUE (attr); arg && TREE_CODE (arg) == TREE_LIST;
> diff --git a/gcc/testsuite/g++.dg/parse/error64.C b/gcc/testsuite/g++.dg/parse/error64.C
> new file mode 100644
> index 00000000000..87848a58c27
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/error64.C
> @@ -0,0 +1,4 @@
> +// PR c++/96637
> +// { dg-do compile }
> +
> +void foo(int[] alignas[1] alignas(1)){} // { dg-error "" }
> 
> base-commit: 9ae8b993cd362e8aea4f65580aaf1453120207f2


  parent reply	other threads:[~2022-05-24 12:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29 14:12 Marek Polacek
2022-05-24 11:41 ` Marek Polacek
2022-05-24 11:59 ` Prathamesh Kulkarni
2022-05-24 12:40   ` Marek Polacek
2022-05-24 12:22 ` Jason Merrill [this message]
2022-05-25 18:49   ` Marek Polacek
2022-05-25 19:51     ` Jason Merrill

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=e310ca51-f355-3799-617b-239536f3ef87@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).