public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8633] attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634]
@ 2024-04-21  4:09 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-04-21  4:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1

commit r13-8633-g2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Apr 15 10:25:22 2024 +0200

    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)

Diff:
---
 gcc/attribs.cc                      | 7 ++++++-
 gcc/testsuite/g++.dg/ext/attrib68.C | 8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 080b95928eb..24818c76f70 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -480,7 +480,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 00000000000..be3b1108491
--- /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'" }
+};

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-21  4:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-21  4:09 [gcc r13-8633] attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634] Jakub Jelinek

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).