typedef unsigned long L __attribute__ ((aligned)); typedef unsigned long L __attribute__ ((aligned)); template <typename T> struct S { union U { L l; } u; }; S <int> s; ICEs with -g, TYPE_NAME seems to be garbage. The problem is that handle_aligned_attribute first (with L as decl): tree tt = TREE_TYPE (decl); *type = build_variant_type_copy (*type); DECL_ORIGINAL_TYPE (decl) = tt; TYPE_NAME (*type) = decl; TREE_USED (*type) = TREE_USED (decl); TREE_TYPE (decl) = *type; then duplicate_decls is called on the L olddecl (with new L as newdecl), where TYPE_NAME (TREE_TYPE (olddecl)) == olddecl and TYPE_NAME (TREE_TYPE (newdecl)) == newdecl, in merge_types newdecl's type wins, and eventually ggc_free (newdecl); So, either something should have changed TYPE_NAME (newtype) from newdecl to olddecl before ggc_free (I guess that would be preferred, but can't it be TYPE_NAME of other related types too?), or we shouldn't ggc_free TYPE_DECLs. Jason, can you please look into this?
Confirmed. Even shorter testcase (which crashes since GCC 4.0.0): ===================================================== typedef unsigned L __attribute__ ((aligned)); typedef unsigned L __attribute__ ((aligned)); L l; ===================================================== bug.cc:4:4: internal compiler error: tree check: expected identifier_node, have <invalid tree code> in modified_type_die, at dwarf2out.c:10376 L l; ^ 0xd15bb4 tree_check_failed(tree_node const*, char const*, int, char const*, ...) ../../gcc/gcc/tree.c:9301 0x8844b0 tree_check ../../gcc/gcc/tree.h:2674 0x8844b0 modified_type_die ../../gcc/gcc/dwarf2out.c:10376 0x8859b9 add_type_attribute ../../gcc/gcc/dwarf2out.c:16717 0x892dd0 gen_variable_die ../../gcc/gcc/dwarf2out.c:18621 0x87eea1 gen_decl_die ../../gcc/gcc/dwarf2out.c:20294 0xb17633 emit_debug_global_declarations(tree_node**, int) ../../gcc/gcc/toplev.c:531 0x55a520 wrapup_globals_for_namespace(tree_node*, void*) ../../gcc/gcc/cp/decl.c:876 0x55759c walk_namespaces_r ../../gcc/gcc/cp/decl.c:843 0x625533 cp_write_global_declarations() ../../gcc/gcc/cp/decl2.c:4455 Please submit a full bug report, [etc.]
re-confirmed on trunk.
Author: jason Date: Tue Jan 28 04:31:30 2014 New Revision: 207169 URL: http://gcc.gnu.org/viewcvs?rev=207169&root=gcc&view=rev Log: PR c++/54652 * decl.c (duplicate_decls): Always use oldtype for TYPE_DECL. Added: trunk/gcc/testsuite/g++.dg/ext/attrib48.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c
Author: jason Date: Tue Jan 28 13:45:08 2014 New Revision: 207191 URL: http://gcc.gnu.org/viewcvs?rev=207191&root=gcc&view=rev Log: PR c++/54652 * decl.c (duplicate_decls): Always use oldtype for TYPE_DECL. Added: branches/gcc-4_8-branch/gcc/testsuite/g++.dg/ext/attrib48.C Modified: branches/gcc-4_8-branch/gcc/cp/ChangeLog branches/gcc-4_8-branch/gcc/cp/decl.c
Fixed.
Author: jason Date: Tue Jan 28 13:51:15 2014 New Revision: 207192 URL: http://gcc.gnu.org/viewcvs?rev=207192&root=gcc&view=rev Log: PR c++/54652 * decl.c (duplicate_decls): Always use oldtype for TYPE_DECL. Added: branches/gcc-4_7-branch/gcc/testsuite/g++.dg/ext/attrib48.C Modified: branches/gcc-4_7-branch/gcc/cp/ChangeLog branches/gcc-4_7-branch/gcc/cp/decl.c