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 via email to