[PR59319] output friends in debug info

Jason Merrill jason@redhat.com
Fri Aug 26 16:13:00 GMT 2016


On Fri, Aug 19, 2016 at 2:46 PM, Alexandre Oliva <aoliva@redhat.com> wrote:
> Handling non-template friends is kind of easy, but it required a bit
> of infrastructure in dwarf2out to avoid (i) forcing debug info for
> unused types or functions: DW_TAG_friend DIEs are only emitted if
> their DW_AT_friend DIE is emitted, and (ii) creating DIEs for such
> types or functions just to have them discarded at the end.  To this
> end, I introduced a list (vec, actually) of types with friends,
> processed at the end of the translation unit, and a list of
> DW_TAG_friend DIEs that, when we're pruning unused types, reference
> DIEs that are still not known to be used, revisited after we finish
> deciding all other DIEs, so that we prune DIEs that would have
> referenced pruned types or functions.
>
> Handlig template friends turned out to be trickier: there's no
> representation in DWARF for templates.  I decided to give debuggers as
> much information as possible, enumerating all specializations of
> friend templates and outputting DW_TAG_friend DIEs referencing them as
> well,

This makes sense, though I'm concerned about the impact on DWARF
optimizers.  I suppose we can teach dwz to use the maximal set of
friends...

> but marking them as DW_AT_artificial to indicate they're not
> explicitly stated in the source code.

This seems unnecessary; there is no semantic difference for a
particular specialization depending on whether it became a friend
directly or from its template.

> This attribute is not valid for
> DW_TAG_friend, so it's only emitted in non-strict mode.  The greatest
> challenge was to enumerate all specializations of a template.  It
> looked trivial at first, given DECL_TEMPLATE_INSTANTIATIONS, but in
> some of the testcases, cases it wouldn't list any specializations, and
> in others it would list only some of them.

Hmm, I would expect it to work where it's documented to be meaningful:
namespace-scope functions and classes.  But looking more closely I see
that for functions, it is only maintained before the function template
is defined.  That should be simple enough to change.

> I couldn't figure out the
> logic behind that, and it seemed clear from the documentation of this
> macro that at least in some cases it wouldn't hold the list, so I
> ended up writing code to look for specializations in the hashtables of
> decl or type specializations.  That worked fine, but it's not exactly
> an efficient way to obtain the desired information, at least in some
> cases.

> - should we output specializations of friend templates as friends even
>   in strict mode?  Currently we output them with DW_AT_artificial in
>   non-strict mode, and without the artificial mark in strict mode.
>
> - is there any way we can use DECL_TEMPLATE_INSTANTIATIONS reliably to
>   enumerate the specializations of a friend template, or at least tell
>   when it can be used?
>
> - I haven't used local_specializations, should I?  I was a bit
>   confused about the apparently unused local_specialization_stack,
>   too.

No, local_specializations is just for function-local decls.

Jason



More information about the Gcc-patches mailing list