public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: fix ICE on invalid attributes [PR96637]
Date: Fri, 29 Apr 2022 10:12:33 -0400	[thread overview]
Message-ID: <20220429141233.41897-1-polacek@redhat.com> (raw)

This patch fixes crashes with invalid attributes.  Arguably it could
make sense to assert seen_error() too.

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
-- 
2.35.1


             reply	other threads:[~2022-04-29 14:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29 14:12 Marek Polacek [this message]
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
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=20220429141233.41897-1-polacek@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).