diff options
author | Jason Merrill <jason@redhat.com> | 2007-11-19 16:35:13 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2007-11-19 16:35:13 -0500 |
commit | 4009f2e7f047aafc40fc9a27d884497e87ae0c05 (patch) | |
tree | 1d16dbdc75464cebb92ce8862847635b43953c3f /gcc/tree.c | |
parent | 4d4447b56b603b0786a0de3601ba45618dc6816c (diff) | |
download | gcc-4009f2e7f047aafc40fc9a27d884497e87ae0c05.zip gcc-4009f2e7f047aafc40fc9a27d884497e87ae0c05.tar.gz gcc-4009f2e7f047aafc40fc9a27d884497e87ae0c05.tar.bz2 |
PR debug/29436, c/32326
PR debug/29436, c/32326
* tree.c (build_type_attribute_qual_variant): Refuse to make
a distinct copy of a struct/enum type. Use build_distinct_type_copy.
* doc/extend.texi (Type Attributes): Don't encourage people to add
attributes to struct/enum types in a typedef. Fix
transparent_union example.
* tree-inline.c (remap_type_1): Remove code that's redundant with
remap_type.
(build_duplicate_type): Set id.copy_decl.
* c-common.c (handle_transparent_union_attribute): Simplify logic.
From-SVN: r130297
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -3666,15 +3666,26 @@ build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) tree ntype; enum tree_code code = TREE_CODE (ttype); - ntype = copy_node (ttype); + /* Building a distinct copy of a tagged type is inappropriate; it + causes breakage in code that expects there to be a one-to-one + relationship between a struct and its fields. + build_duplicate_type is another solution (as used in + handle_transparent_union_attribute), but that doesn't play well + with the stronger C++ type identity model. */ + if (TREE_CODE (ttype) == RECORD_TYPE + || TREE_CODE (ttype) == UNION_TYPE + || TREE_CODE (ttype) == QUAL_UNION_TYPE + || TREE_CODE (ttype) == ENUMERAL_TYPE) + { + warning (OPT_Wattributes, + "ignoring attributes applied to %qT after definition", + TYPE_MAIN_VARIANT (ttype)); + return build_qualified_type (ttype, quals); + } - TYPE_POINTER_TO (ntype) = 0; - TYPE_REFERENCE_TO (ntype) = 0; - TYPE_ATTRIBUTES (ntype) = attribute; + ntype = build_distinct_type_copy (ttype); - /* Create a new main variant of TYPE. */ - TYPE_MAIN_VARIANT (ntype) = ntype; - TYPE_NEXT_VARIANT (ntype) = 0; + TYPE_ATTRIBUTES (ntype) = attribute; set_type_quals (ntype, TYPE_UNQUALIFIED); hashcode = iterative_hash_object (code, hashcode); |