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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Re-confirmed.  We can simply elide the assert, the recursion is harmless since
in this case TREE_ASM_WRITTEN (name) is set already via

(gdb) bt
#0  gen_typedef_die (decl=<type_decl 0x7ffff69da500 a>, 
    context_die=<dw_die_ref 0x7ffff6834050 DW_TAG_class_type
<parent=0x7ffff6834000 DW_TAG_compile_unit>>) at
../../src/gcc/gcc/dwarf2out.cc:26265
#1  0x00000000016685a4 in gen_decl_die (decl=<type_decl 0x7ffff69da500 a>, 
    origin=<tree 0x0>, ctx=0x7fffffffb620, 
    context_die=<dw_die_ref 0x7ffff6834050 DW_TAG_class_type
<parent=0x7ffff6834000 DW_TAG_compile_unit>>) at
../../src/gcc/gcc/dwarf2out.cc:27280
#2  0x00000000016646b6 in gen_member_die (type=<record_type 0x7ffff69bf348 T>, 
    context_die=<dw_die_ref 0x7ffff6834050 DW_TAG_class_type
<parent=0x7ffff6834000 DW_TAG_compile_unit>>) at
../../src/gcc/gcc/dwarf2out.cc:26089
#3  0x0000000001664e03 in gen_struct_or_union_type_die (
    type=<record_type 0x7ffff69bf348 T>, 
    context_die=<dw_die_ref 0x7ffff6834000 DW_TAG_compile_unit>, 
    usage=DINFO_USAGE_DIR_USE) at ../../src/gcc/gcc/dwarf2out.cc:26185

which runs into a similar assert that passes:

26268     if (DECL_ORIGINAL_TYPE (decl))
26269       {
26270         type = DECL_ORIGINAL_TYPE (decl);
26271         if (type == error_mark_node)
26272           return;
26273
26274         gcc_assert (type != TREE_TYPE (decl));

    DIE    0: DW_TAG_class_type (0x7ffff6834050)
      abbrev id: 0 offset: 0 mark: 0
      DW_AT_name: "T<int>"
      DW_AT_byte_size: 1
      DW_AT_decl_file: "t.ii" (0)
      DW_AT_decl_line: 1
      DW_AT_decl_column: 27
        DIE    0: DW_TAG_structure_type (0x7ffff68340a0)
          abbrev id: 0 offset: 0 mark: 0
          DW_AT_name: "a"
          DW_AT_declaration: 1
        DIE    0: DW_TAG_typedef (0x7ffff68340f0)
          abbrev id: 0 offset: 0 mark: 0
          DW_AT_name: "a"
          DW_AT_decl_file: "t.ii" (0)
          DW_AT_decl_line: 3
          DW_AT_decl_column: 21

it was Jason who added this assert in r0-42720-g29b91443e955b9, the
following avoids the ICE in this PR.

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index ed7d9402200..8b396866d24 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -26431,7 +26431,7 @@ gen_type_die_with_usage (tree type, dw_die_ref
context_die,
        }

       /* Prevent broken recursion; we can't hand off to the same type.  */
-      gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
+      gcc_assert (DECL_ORIGINAL_TYPE (name) != type || TREE_ASM_WRITTEN
(name));

       /* Give typedefs the right scope.  */
       context_die = scope_die_for (type, context_die);

but we could also simply not do anything if name has alread been emitted:

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index ed7d9402200..d0a29efe633 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -26419,10 +26419,10 @@ gen_type_die_with_usage (tree type, dw_die_ref
context_die,
      for the parent typedef which TYPE is a type of.  */
   if (typedef_variant_p (type))
     {
-      if (TREE_ASM_WRITTEN (type))
+      tree name = TYPE_NAME (type);
+      if (TREE_ASM_WRITTEN (type) || TREE_ASM_WRITTEN (name))
        return;

-      tree name = TYPE_NAME (type);
       tree origin = decl_ultimate_origin (name);
       if (origin != NULL && origin != name)
        {

I suppose the existing TREE_ASM_WRITTEN (type) check is off in this regard
and instead the following might be better overall?  I'm going to test this.

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index ed7d9402200..d4c51554e3e 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -26419,10 +26419,10 @@ gen_type_die_with_usage (tree type, dw_die_ref
context_die,
      for the parent typedef which TYPE is a type of.  */
   if (typedef_variant_p (type))
     {
-      if (TREE_ASM_WRITTEN (type))
+      tree name = TYPE_NAME (type);
+      if (TREE_ASM_WRITTEN (name))
        return;

-      tree name = TYPE_NAME (type);
       tree origin = decl_ultimate_origin (name);
       if (origin != NULL && origin != name)
        {
@@ -26436,8 +26436,6 @@ gen_type_die_with_usage (tree type, dw_die_ref
context_die,
       /* Give typedefs the right scope.  */
       context_die = scope_die_for (type, context_die);

-      TREE_ASM_WRITTEN (type) = 1;
-
       gen_decl_die (name, NULL, NULL, context_die);
       return;
     }

Reply via email to