On Tue, 25 Sep 2018, Jason Merrill wrote:

> On Tue, Sep 25, 2018 at 6:34 AM, Richard Biener <rguent...@suse.de> wrote:
> >
> > Hi,
> >
> > the following two patches both "fix" the immediate issue of gdb
> > asserting with
> >
> > ../../gdb/dwarf2read.c:9730: internal-error: void
> > dw2_add_symbol_to_list(symbol*, pending**): Assertion `(*listhead) == NULL
> > || (SYMBOL_LANGUAGE ((*listhead)->symbol[0]) == SYMBOL_LANGUAGE (symbol))'
> > failed.
> >
> > on most LTO compiled objects now.  I tracked this down to us generating
> > bogus DWARF (as I read it), specifically an inline instance that is
> > output not as DW_TAG_inlined_subroutine but represented as
> > DW_TAG_lexical_block (but otherwise with same children and abstract
> > origin).  This is because we do have (quite a lot :/) inlined calls
> > with LOCATION_LOCUS (gimple_location (stmt)) == UNKNOWN_LOCATION
> > and thus inlined_function_outer_scope_p returning false on the
> > BLOCK the inliner generates.
> >
> > A third yet untested alternative would be to store the combined
> > locus|BLOCK location in BLOCK_SOURCE_LOCATION and in
> > inlined_function_outer_scope_p check for literal UNKNOWN_LOCATION
> > instead of looking at LOCATION_LOCUS.  We'd have to properly
> > remap the locus in remap_block (which may be a chicken-and-egg issue)
> > to not run foul of what I fixed with r196542.  But somehow that
> > runs into issues with the new debug notes Alex added last year.
> > Similarly keying on BLOCK_ABSTRACT_ORIGIN rather than
> > BLOCK_SOURCE_LOCATION in inlined_function_outer_scope_p.
> >
> > Any ideas?  The least fallout is probably produced by the
> > BUILTINS_LOCATION "hack" (but dwarf2out.c assumes that the
> > locations are sensible and thus will output some "interesting"
> > src-coords for the lexical block, <built-in>:0 respectively).
> 
> Is there a reason not to use DECL_SOURCE_LOCATION (fn)?

I guess that would work as well (and iff that's zero, like for
artificial functions, BUILTINS_LOCATION might again be a valid fallback).
It would still have src-coords on the lexical block that might be
different as one would expect, but it might be good enough.

So, would you be happy with the following?

Btw, I opened sourceware/23712 for the original issue in gdb which
still triggers (but less often, now on sane DWARF).

Thanks,
Richard.

2018-09-25  Richard Biener  <rguent...@suse.de>

        PR debug/87428
        PR debug/87362
        * tree-inline.c (expand_call_inline): When the location
        of the call is UNKNOWN_LOCATION use DECL_SOURCE_LOCATION
        or BUILTINS_LOCATION for the BLOCK_SOURCE_LOCATION of
        the inserted BLOCK to make inlined_function_outer_scope_p
        recognize it.
        * dwarf2out.c (add_call_src_coords_attributes): Do not add
        coords for reserved locations.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 264564)
+++ gcc/dwarf2out.c     (working copy)
@@ -23913,6 +23907,10 @@ gen_label_die (tree decl, dw_die_ref con
 static inline void
 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
 {
+  /* We can end up with BUILTINS_LOCATION here.  */
+  if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
+    return;
+
   expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
 
   if (dwarf_version >= 3 || !dwarf_strict)
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c   (revision 264564)
+++ gcc/tree-inline.c   (working copy)
@@ -4527,10 +4527,16 @@ expand_call_inline (basic_block bb, gimp
      not refer to them in any way to not break GC for locations.  */
   if (gimple_block (stmt))
     {
+      /* We do want to assign a not UNKNOWN_LOCATION BLOCK_SOURCE_LOCATION
+         to make inlined_function_outer_scope_p return true on this BLOCK.  */
+      location_t loc = LOCATION_LOCUS (gimple_location (stmt));
+      if (loc == UNKNOWN_LOCATION)
+       loc = LOCATION_LOCUS (DECL_SOURCE_LOCATION (fn));
+      if (loc == UNKNOWN_LOCATION)
+       loc = BUILTINS_LOCATION;
       id->block = make_node (BLOCK);
       BLOCK_ABSTRACT_ORIGIN (id->block) = fn;
-      BLOCK_SOURCE_LOCATION (id->block) 
-       = LOCATION_LOCUS (gimple_location (stmt));
+      BLOCK_SOURCE_LOCATION (id->block) = loc;
       prepend_lexical_block (gimple_block (stmt), id->block);
     }
 

Reply via email to