From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 4AB0D3858C60; Sun, 21 Apr 2024 04:09:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AB0D3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713672567; bh=jQnW77fBG/yYRF0Xlts2BS4JWI5kAFea+AFvdvuK0Ec=; h=From:To:Subject:Date:From; b=Dc5P6Lpp5Z6BdbePthGoN7pzLvr12i2cjmDgjmSkawpCQchyKRxItUD1yraGckaZs XU3zmb5mfsZVy+RtRO/DLljdbGGihFl9QXhK4Xzwif3uwheasktjfxbsBeHFGqZoOo 6RmmnEitbL1hp8HZIdphvzvSe0C/hqJniuNvr+74= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8633] attribs: Don't crash on NULL TREE_TYPE in diag_attr_exclusions [PR114634] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: ed7be7ba6f125cfda7ad07263213cbe02b7e7ced X-Git-Newrev: 2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1 Message-Id: <20240421040927.4AB0D3858C60@sourceware.org> Date: Sun, 21 Apr 2024 04:09:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1 commit r13-8633-g2c85e8def0efd4b0d9d312a1f0cbbee332b4e0d1 Author: Jakub Jelinek 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 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 +struct A +{ + enum { e __attribute__ ((aligned (16))) }; // { dg-error "alignment may not be specified for 'e'" } +};