aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-04-15 10:25:22 +0200
committerJakub Jelinek <jakub@redhat.com>2024-06-11 12:35:36 +0200
commitbb21a7de31183108bdb2489f987deaf94e4985b6 (patch)
treec80090452f91ed362dec305a4e349cdca4433d74
parente9b960edb01449786a29a8d196c476bfefc4f243 (diff)
downloadgcc-bb21a7de31183108bdb2489f987deaf94e4985b6.zip
gcc-bb21a7de31183108bdb2489f987deaf94e4985b6.tar.gz
gcc-bb21a7de31183108bdb2489f987deaf94e4985b6.tar.bz2
attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]
The enumerator still doesn't have TREE_TYPE set but diag_attr_exclusions assumes that all decls must have types. I think it is better in something as unimportant as diag_attr_exclusions to be more robust, if there is no type, it can just diagnose exclusions on the DECL_ATTRIBUTES, like for types it only diagnoses it on TYPE_ATTRIBUTES. 2024-04-15 Jakub Jelinek <jakub@redhat.com> PR c++/114634 * attribs.cc (diag_attr_exclusions): Set attrs[1] to NULL_TREE for decls with NULL TREE_TYPE. * g++.dg/ext/attrib68.C: New test. (cherry picked from commit 7ec54f5fdfec298812a749699874db4d6a7246bb)
-rw-r--r--gcc/attribs.cc7
-rw-r--r--gcc/testsuite/g++.dg/ext/attrib68.C8
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index f73e00b..3bf4253 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -479,7 +479,12 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
if (DECL_P (node))
{
attrs[0] = DECL_ATTRIBUTES (node);
- attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+ if (TREE_TYPE (node))
+ attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
+ else
+ /* TREE_TYPE can be NULL e.g. while processing attributes on
+ enumerators. */
+ attrs[1] = NULL_TREE;
}
else
{
diff --git a/gcc/testsuite/g++.dg/ext/attrib68.C b/gcc/testsuite/g++.dg/ext/attrib68.C
new file mode 100644
index 0000000..be3b110
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib68.C
@@ -0,0 +1,8 @@
+// PR c++/114634
+// { dg-do compile }
+
+template <int N>
+struct A
+{
+ enum { e __attribute__ ((aligned (16))) }; // { dg-error "alignment may not be specified for 'e'" }
+};