From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id CA8C73858D28; Sat, 30 Apr 2022 14:28:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA8C73858D28 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-57] c-family: attribute ((aligned, mode)) [PR100545] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 66d1e440e14377a373d0e3d67f478cca4fd14dea X-Git-Newrev: 0aa277bf0b4b794314ab3f11bab438d17b57465d Message-Id: <20220430142836.CA8C73858D28@sourceware.org> Date: Sat, 30 Apr 2022 14:28:36 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Apr 2022 14:28:36 -0000 https://gcc.gnu.org/g:0aa277bf0b4b794314ab3f11bab438d17b57465d commit r13-57-g0aa277bf0b4b794314ab3f11bab438d17b57465d Author: Jason Merrill Date: Fri Apr 15 16:27:05 2022 -0400 c-family: attribute ((aligned, mode)) [PR100545] The problem here was that handle_mode_attribute clobbered the changes of any previous attribute, only copying type qualifiers to the new type. And common_handle_aligned_attribute had previously set up the typedef, so when we later called set_underlying_type it saw DECL_ORIGINAL_TYPE set and just returned, even though handle_mode_attribute had messed up the TREE_TYPE. So, let's fix handle_mode_attribute to copy attributes, alignment, and typedefness to the new type. PR c/100545 gcc/c-family/ChangeLog: * c-attribs.cc (handle_mode_attribute): Copy attributes, aligned, and typedef. * c-common.cc (set_underlying_type): Add assert. gcc/testsuite/ChangeLog: * c-c++-common/attr-mode-1.c: New test. * c-c++-common/attr-mode-2.c: New test. Diff: --- gcc/c-family/c-attribs.cc | 16 +++++++++++++++- gcc/c-family/c-common.cc | 7 ++++--- gcc/testsuite/c-c++-common/attr-mode-1.c | 4 ++++ gcc/testsuite/c-c++-common/attr-mode-2.c | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 111a33f405a..b1953a45f9b 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -2199,7 +2199,21 @@ handle_mode_attribute (tree *node, tree name, tree args, return NULL_TREE; } - *node = build_qualified_type (typefm, TYPE_QUALS (type)); + /* Copy any quals and attributes to the new type. */ + *node = build_type_attribute_qual_variant (typefm, TYPE_ATTRIBUTES (type), + TYPE_QUALS (type)); + if (TYPE_USER_ALIGN (type)) + *node = build_aligned_type (*node, TYPE_ALIGN (type)); + + tree decl = node[2]; + if (decl && TYPE_NAME (type) == decl) + { + /* Set up the typedef all over again. */ + DECL_ORIGINAL_TYPE (decl) = NULL_TREE; + TREE_TYPE (decl) = *node; + set_underlying_type (decl); + *node = TREE_TYPE (decl); + } } return NULL_TREE; diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index bb0544eeaea..730faa9e87f 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -8153,15 +8153,16 @@ check_missing_format_attribute (tree ltype, tree rtype) void set_underlying_type (tree x) { - if (x == error_mark_node) + if (x == error_mark_node || TREE_TYPE (x) == error_mark_node) return; if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE) { if (TYPE_NAME (TREE_TYPE (x)) == 0) TYPE_NAME (TREE_TYPE (x)) = x; } - else if (TREE_TYPE (x) != error_mark_node - && DECL_ORIGINAL_TYPE (x) == NULL_TREE) + else if (DECL_ORIGINAL_TYPE (x)) + gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x); + else { tree tt = TREE_TYPE (x); DECL_ORIGINAL_TYPE (x) = tt; diff --git a/gcc/testsuite/c-c++-common/attr-mode-1.c b/gcc/testsuite/c-c++-common/attr-mode-1.c new file mode 100644 index 00000000000..04a2431f5e5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/attr-mode-1.c @@ -0,0 +1,4 @@ +// PR c/100545 +// { dg-additional-options -g } + +typedef int fatp_t __attribute__((aligned, mode(SI))); diff --git a/gcc/testsuite/c-c++-common/attr-mode-2.c b/gcc/testsuite/c-c++-common/attr-mode-2.c new file mode 100644 index 00000000000..de65f49c6b6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/attr-mode-2.c @@ -0,0 +1,4 @@ +typedef int I; +int x; +I y __attribute__ ((mode(QI))); +extern I x;