diff options
author | Jason Merrill <jason@redhat.com> | 2022-04-15 16:27:05 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-04-30 05:45:05 -0400 |
commit | 0aa277bf0b4b794314ab3f11bab438d17b57465d (patch) | |
tree | 10bf1b97ecf8ad30860c0fadf657c01b9d289e51 /gcc/c-family/c-attribs.cc | |
parent | 66d1e440e14377a373d0e3d67f478cca4fd14dea (diff) | |
download | gcc-0aa277bf0b4b794314ab3f11bab438d17b57465d.zip gcc-0aa277bf0b4b794314ab3f11bab438d17b57465d.tar.gz gcc-0aa277bf0b4b794314ab3f11bab438d17b57465d.tar.bz2 |
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.
Diffstat (limited to 'gcc/c-family/c-attribs.cc')
-rw-r--r-- | gcc/c-family/c-attribs.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 111a33f..b1953a4 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; |