https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67289

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-11-26
                 CC|                            |jason at redhat dot com,
                   |                            |rguenther at suse dot de
     Ever confirmed|0                           |1

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
I reproduced the problem on firefox. What happens is that we call
DECL_ASSEMBER_NAME on TYPE_DECL before its visibility is finalized. This means
that the name "<anon>" is produced and we never revisit it to real assembler
name.
The DECL_ASSEMBLER_NAME on the TYPE_DECL is triggered by:

#0  contains_struct_check (__g=0x169b10a
<mangle_decl(tree_node*)::__FUNCTION__> "mangle_decl", __l=3602, __f=0x1592b00
"../../gcc/cp/mangle.c", __s=TS_DECL_MINIMAL, __t=0x7fffe53e17b8)
    at ../../gcc/tree.h:3105
#1  mangle_decl (decl=0x7fffe53e17b8) at ../../gcc/cp/mangle.c:3602
#2  0x0000000000fb64f4 in decl_assembler_name (decl=0x7fffe53e17b8) at
../../gcc/tree.c:670
#3  0x00000000009ca36e in add_linkage_attr (die=0x7fffe5393be0, decl=<optimized
out>) at ../../gcc/dwarf2out.c:17255
#4  0x00000000009edb45 in gen_typedef_die (context_die=0x7fffe5393b90,
decl=0x7fffe53e17b8) at ../../gcc/dwarf2out.c:20633
#5  gen_typedef_die (decl=0x7fffe53e17b8, context_die=0x7fffe5393b90) at
../../gcc/dwarf2out.c:20569
#6  0x00000000009d4c76 in gen_decl_die (decl=0x7fffe53e17b8, origin=<optimized
out>, context_die=0x7fffe5393b90) at ../../gcc/dwarf2out.c:21522
#7  0x00000000009d87f7 in gen_type_die_with_usage (type=0x7fffe53e0b28,
context_die=0x7fffe5393b90, usage=DINFO_USAGE_DIR_USE) at
../../gcc/dwarf2out.c:20780
#8  0x00000000009d9f47 in gen_type_die (type=0x7fffe53e0b28,
context_die=<optimized out>) at ../../gcc/dwarf2out.c:20932
#9  0x00000000009d483e in gen_decl_die (decl=0x7fffe53e12f8, origin=<optimized
out>, context_die=0x7fffe5393b90) at ../../gcc/dwarf2out.c:21519
#10 0x00000000009d6d1b in gen_member_die (context_die=0x7fffe5393b90,
type=0x7fffe53e09d8) at ../../gcc/dwarf2out.c:20411
#11 gen_struct_or_union_type_die (usage=<optimized out>,
context_die=0x7ffff6b01000, type=0x7fffe53e09d8) at ../../gcc/dwarf2out.c:20516
#12 gen_tagged_type_die (usage=<optimized out>, context_die=0x7ffff6b01000,
type=0x7fffe53e09d8) at ../../gcc/dwarf2out.c:20717
#13 gen_tagged_type_die (type=0x7fffe53e09d8, context_die=<optimized out>,
usage=<optimized out>) at ../../gcc/dwarf2out.c:20658
#14 0x00000000009d8d9a in gen_type_die_with_usage (type=0x7fffe53e09d8,
context_die=0x7ffff6b01000, usage=DINFO_USAGE_DIR_USE) at
../../gcc/dwarf2out.c:20877
#15 0x00000000009d9f47 in gen_type_die (type=0x7fffe53e09d8,
context_die=<optimized out>) at ../../gcc/dwarf2out.c:20932
#16 0x00000000009d483e in gen_decl_die (decl=0x7fffe5392390, origin=<optimized
out>, context_die=0x7ffff6b01000) at ../../gcc/dwarf2out.c:21519
#17 0x00000000009d5bbd in dwarf2out_decl (decl=0x7fffe5392390) at
../../gcc/dwarf2out.c:21978
#18 0x00000000009d5eb3 in dwarf2out_type_decl (decl=<optimized out>,
local=<optimized out>) at ../../gcc/dwarf2out.c:21688
#19 dwarf2out_type_decl (decl=<optimized out>, local=<optimized out>) at
../../gcc/dwarf2out.c:21683
#20 0x0000000000c582fc in rest_of_type_compilation (type=0x7fffe53e09d8,
toplev=1) at ../../gcc/passes.c:335
#21 0x00000000006d161f in finish_struct_1 (t=0x7fffe53e09d8) at
../../gcc/cp/class.c:6776

This happens by:
          type = TREE_TYPE (decl);

          if (type == error_mark_node)
            return;

          if (is_naming_typedef_decl (TYPE_NAME (type)))
            {
              /* Here, we are in the case of decl being a typedef naming
                 an anonymous type, e.g:
                     typedef struct {...} foo;
                 In that case TREE_TYPE (decl) is not a typedef variant
                 type and TYPE_NAME of the anonymous type is set to the
                 TYPE_DECL of the typedef. This construct is emitted by
                 the C++ FE.

                 TYPE is the anonymous struct named by the typedef
                 DECL. As we need the DW_AT_type attribute of the
                 DW_TAG_typedef to point to the DIE of TYPE, let's
                 generate that DIE right away. add_type_attribute
                 called below will then pick (via lookup_type_die) that
                 anonymous struct DIE.  */
              if (!TREE_ASM_WRITTEN (type))
                gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);

              /* This is a GNU Extension.  We are adding a
                 DW_AT_linkage_name attribute to the DIE of the
                 anonymous struct TYPE.  The value of that attribute
                 is the name of the typedef decl naming the anonymous
                 struct.  This greatly eases the work of consumers of
                 this debug info.  */
              add_linkage_attr (lookup_type_die (type), decl);
            }

lookup_type_die does:

static void
add_linkage_attr (dw_die_ref die, tree decl)
{
  const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));

  /* Mimic what assemble_name_raw does with a leading '*'.  */
  if (name[0] == '*')
    name = &name[1];

  if (dwarf_version >= 4)
    add_AT_string (die, DW_AT_linkage_name, name);
  else
    add_AT_string (die, DW_AT_MIPS_linkage_name, name);
}

I wonder what that GNU extensionis about. Clearly attributing the types with
assembler name <anon> is not going to win anything. Moreover I think with early
debug we now apparently manage to consider typedefs anonymous when they really
are not.  The TREE_PUBLIC is later revisited by:

#0  set_linkage_according_to_type (decl=0x7fffe53e12f8) at
../../gcc/cp/class.c:757
#1  0x00000000006d4fbf in reset_type_linkage_1 (type=0x7fffe53e0b28) at
../../gcc/cp/decl2.c:2632
#2  0x00000000007efa08 in binding_table_foreach (table=0x7fffe53b2f00,
proc=0x6d5090 <bt_reset_linkage_1(binding_entry, void*)>, data=0x0) at
../../gcc/cp/name-lookup.c:258
#3  0x00000000006e1b19 in reset_type_linkage (type=0x7fffe53e09d8) at
../../gcc/cp/decl2.c:2700
#4  0x0000000000628374 in grokdeclarator (declarator=0x219ff00,
declspecs=<optimized out>, decl_context=NORMAL, initialized=0,
attrlist=0x7fffffffd618) at ../../gcc/cp/decl.c:10700
#5  0x000000000062b606 in start_decl (declarator=0x219ff00,
declspecs=0x7fffffffd730, initialized=0, attributes=0x0, prefix_attributes=0x0,
pushed_scope_p=0x7fffffffd6b0)
    at ../../gcc/cp/decl.c:4788
#6  0x0000000000706fff in cp_parser_init_declarator (parser=0x7ffff1f87f30,
decl_specifiers=0x7fffffffd730, checks=0x0, function_definition_allowed_p=22,
member_p=false, 
    declares_class_or_enum=0, function_definition_p=0x7fffffffd7cf,
maybe_range_for_decl=0x0, init_loc=0x7fffffffd7c8) at
../../gcc/cp/parser.c:18070

Reply via email to