public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: fix ICE on invalid attributes [PR96637]
@ 2022-04-29 14:12 Marek Polacek
  2022-05-24 11:41 ` Marek Polacek
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Marek Polacek @ 2022-04-29 14:12 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-25 19:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 14:12 [PATCH] c++: fix ICE on invalid attributes [PR96637] 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
2022-05-25 18:49   ` Marek Polacek
2022-05-25 19:51     ` 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).