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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
A workaround might be in dwarf2out_function_decl push/pop the decl_die_table
like with a "simple" undo stack:

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 256378)
+++ gcc/dwarf2out.c     (working copy)
@@ -3159,6 +3159,7 @@ struct decl_die_hasher : ggc_ptr_hash<di
 /* A hash table of references to DIE's that describe declarations.
    The key is a DECL_UID() which is a unique number identifying each decl.  */
 static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
+static vec<std::pair<tree, dw_die_ref> > *decl_die_table_undo_stack;

 struct GTY ((for_user)) variable_value_struct {
   unsigned int decl_id;
@@ -5762,7 +5763,10 @@ equate_decl_number_to_die (tree decl, dw
 {
   unsigned int decl_id = DECL_UID (decl);

-  *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
+  dw_die_ref *slot = decl_die_table->find_slot_with_hash (decl, decl_id,
INSERT);
+  if (*slot && decl_die_table_undo_stack)
+    decl_die_table_undo_stack->safe_push (std::make_pair (decl, *slot));
+  *slot = decl_die;
   decl_die->decl_id = decl_id;
 }

@@ -26044,6 +26048,10 @@ dwarf2out_decl (tree decl)
 static void
 dwarf2out_function_decl (tree decl)
 {
+  vec<std::pair<tree, dw_die_ref> > *undo_stack
+    = new vec<std::pair<tree, dw_die_ref> > ();
+  decl_die_table_undo_stack = undo_stack;
+
   dwarf2out_decl (decl);
   call_arg_locations = NULL;
   call_arg_loc_last = NULL;
@@ -26051,6 +26059,15 @@ dwarf2out_function_decl (tree decl)
   tail_call_site_count = -1;
   decl_loc_table->empty ();
   cached_dw_loc_list_table->empty ();
+
+  decl_die_table_undo_stack = NULL;
+  while (! undo_stack->is_empty ())
+    {
+      std::pair<tree, dw_die_ref> op = undo_stack->pop ();
+      equate_decl_number_to_die (op.first, op.second);
+    }
+
+  delete undo_stack;
 }

 /* Output a marker (i.e. a label) for the beginning of the generated code for

Reply via email to