public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10863] dwarf2: Emit DW_TAG_unspecified_parameters even in late DWARF [PR97599]
@ 2021-04-22 16:48 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-22 16:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1a89fa601b0335cedb8ed415f1ef209cf1544002

commit r8-10863-g1a89fa601b0335cedb8ed415f1ef209cf1544002
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Nov 14 09:14:19 2020 +0100

    dwarf2: Emit DW_TAG_unspecified_parameters even in late DWARF [PR97599]
    
    Aldy's PR71855 fix avoided emitting multiple redundant
    DW_TAG_unspecified_parameters sub-DIEs of a single DIE by restricting
    it to early dwarf only.  That unfortunately means if we need to emit
    another DIE for the function (whether it is for LTO, or e.g. because of
    IPA cloning), we don't emit DW_TAG_unspecified_parameters, it remains
    solely in the DW_AT_abstract_origin's referenced DIE.
    But DWARF consumers don't really use DW_TAG_unspecified_parameters
    from there, like we duplicate DW_TAG_formal_parameter sub-DIEs even in the
    clones because either they have some more specific location, or e.g.
    a function clone could have fewer or different argument types etc.,
    they need to assume that originally stdarg function isn't later stdarg etc.
    Unfortunately, while for DW_TAG_formal_parameter sub-DIEs, we can use the
    hash tabs to look the PARM_DECLs if we already have the DIEs, for
    DW_TAG_unspecified_parameters we don't have an easy way to look it up.
    
    The following patch handles it by trying to figure out if we are creating a
    fresh new DIE (in that case we add DW_TAG_unspecified_parameters if it is
    stdarg), or if gen_subprogram_die is called again on an pre-existing DIE
    to fill in some further details (then it will not touch it).
    
    Except for lto, subr_die != old_die would be good enough, but unfortunately
    for LTO the new DIE that will refer to early dwarf created DIE is created
    on the fly during lookup_decl_die.  So the patch tracks if the DIE has
    no children before any children are added to it.
    
    2020-11-14  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/97599
            * dwarf2out.c (gen_subprogram_die): Call
            gen_unspecified_parameters_die even if not early dwarf, but only
            if subr_die is a newly created DIE.
    
    (cherry picked from commit 812258b07c1a80e8dc79a0beb3ec0e17be62f5e5)

Diff:
---
 gcc/dwarf2out.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b1dd03cf0ba..f2d06f1183d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -22722,6 +22722,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
   tree origin = decl_ultimate_origin (decl);
   dw_die_ref subr_die;
   dw_die_ref old_die = lookup_decl_die (decl);
+  bool old_die_had_no_children = false;
 
   /* This function gets called multiple times for different stages of
      the debug process.  For example, for func() in this code:
@@ -22812,6 +22813,9 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
   if (old_die && declaration)
     return;
 
+  if (in_lto_p && old_die && old_die->die_child == NULL)
+    old_die_had_no_children = true;
+
   /* Now that the C++ front end lazily declares artificial member fns, we
      might need to retrofit the declaration into its class.  */
   if (!declaration && !origin && !old_die
@@ -23332,6 +23336,10 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 	  else if (DECL_INITIAL (decl) == NULL_TREE)
 	    gen_unspecified_parameters_die (decl, subr_die);
 	}
+      else if ((subr_die != old_die || old_die_had_no_children)
+	       && prototype_p (TREE_TYPE (decl))
+	       && stdarg_p (TREE_TYPE (decl)))
+	gen_unspecified_parameters_die (decl, subr_die);
     }
 
   if (subr_die != old_die)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-22 16:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 16:48 [gcc r8-10863] dwarf2: Emit DW_TAG_unspecified_parameters even in late DWARF [PR97599] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).