http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60929
--- Comment #2 from Cary Coutant <ccoutant at gcc dot gnu.org> --- Author: ccoutant Date: Fri Apr 25 23:05:14 2014 New Revision: 209812 URL: http://gcc.gnu.org/viewcvs?rev=209812&root=gcc&view=rev Log: Fix a few ICEs and other problems with -fdebug-types-sections. (1) If a function contains a local typedef of an anonymous structure, GCC will generate a typedef DIE in the function, where the typedef DIE points to a structure_type DIE at the top level. That structure_type DIE, if it's a non-POD, can contain ctor and dtor definitions. This causes an assertion in should_move_die_to_comdat to fail, as we have up to now assumed that this could never happen. (2) With --std=c++11, a template parameter can refer to a local type defined within a function. Because that local type doesn't qualify for its own type unit, we copy it as an "unworthy" type into the type unit that refers to it, but we copy too much, leading to a comdat type unit that contains a DIE with subprogram definitions rather than declarations. These DIEs may have DW_AT_low_pc/high_pc or DW_AT_ranges attributes, and consequently can refer to range list entries that don't get emitted because they're not marked when the compile unit is scanned, eventually causing an undefined symbol at link time. (3) When a class template instantiation is moved into a separate type unit, it can bring along a lot of other referenced types into the type unit, especially if the template is derived from another (large) type that does not have an actually have a type definition in a type unit of its own. When there are many instantiations of the same template, we get a lot of duplication, and in the worst case (a template with several parameters, instantiated multiple times along each dimension), GCC can end up taking a long time and exhausting available memory. This combinatorial explosion is being caused by copy_decls_walk, where it finds a type DIE that is referenced by the type unit, but is not itself a type unit, and copies a declaration for that type into the type unit in order to resolve the reference within the type unit. In the process, copy_decls_walk also copies all of the children of that DIE. In the case of a base class with member function templates, every one of the instantiated member functions is copied into every type unit that references the base class. gcc/ PR debug/60929 * dwarf2out.c (should_move_die_to_comdat): A type definition can contain a subprogram definition, but don't move it to a comdat unit. (clone_as_declaration): Copy DW_AT_abstract_origin attribute. (generate_skeleton_bottom_up): Remove DW_AT_object_pointer attribute from original DIE. (clone_tree_hash): Rename to... (clone_tree_partial): ...this; change callers. Copy DW_TAG_subprogram DIEs as declarations. (copy_decls_walk): Don't copy children of a declaration into a type unit. gcc/testsuite/ PR debug/60929 * g++.dg/debug/dwarf2/dwarf4-nested.C: New test case. * g++.dg/debug/dwarf2/dwarf4-typedef.C: Add -fdebug-types-section flag. Added: trunk/gcc/testsuite/g++.dg/debug/dwarf2/dwarf4-nested.C Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/debug/dwarf2/dwarf4-typedef.C