On Mon, 17 Mar 2025, Jason Merrill wrote:
> On 3/5/25 10:21 AM, Richard Biener wrote:
> > There's a sanity check in gen_type_die_with_usage that trips
> > unnecessarily for a case where the relevant DIE has already been
> > generated successfully in other ways. The following keys the
> > existing TREE_ASM_WRITTEN check on the correct object, honoring
> > this and does nothing instead of ICEing for the testcase at hand.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> >
> > OK?
> >
> > Thanks,
> > Richard.
> >
> > PR debug/101533
> > * dwarf2out.cc (gen_type_die_with_usage): When we have
> > output the typedef already do nothing for a typedef variant.
> > Do not set TREE_ASM_WRITTEN on the type itself, recursion
> > on the name should do this.
>
> But it doesn't; nothing sets TREE_ASM_WRITTEN on the variant type, that's why
> the existing test fails. We could decide that it's OK that we never set the
> flag on the variant type, but this comment is false.
OK, it's probably mis-worded. I was refering to gen_typedef_die
setting (and checking) TREE_ASM_WRITTEN. I see there's the
is_redundant_typedef path in gen_decl_die:
if (is_redundant_typedef (decl))
gen_type_die (TREE_TYPE (decl), context_die);
else
/* Output a DIE to represent the typedef itself. */
gen_typedef_die (decl, context_die);
somehow I convinced myself we're always going gen_typedef_die, but
I can't see that triviality now...
But since it passed testing ...
I'll note the above recurses with TREE_TYPE (name) rather than the
recursion we check in gen_type_die_with_usage:
/* Prevent broken recursion; we can't hand off to the same type. */
gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
it's a bit of a maze. But I'm fine with reworking when the fix runs
into another issue out in the wild.
> OK with the comment corrected, perhaps by just removing everything after the
> comma.
I'll go ahead with this tomorrow unless you have more insights here.
Richard.
> > * g++.dg/debug/pr101533.C: New testcase.
> > ---
> > gcc/dwarf2out.cc | 6 ++----
> > gcc/testsuite/g++.dg/debug/pr101533.C | 11 +++++++++++
> > 2 files changed, 13 insertions(+), 4 deletions(-)
> > create mode 100644 gcc/testsuite/g++.dg/debug/pr101533.C
> >
> > 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;
> > }
> > diff --git a/gcc/testsuite/g++.dg/debug/pr101533.C
> > b/gcc/testsuite/g++.dg/debug/pr101533.C
> > new file mode 100644
> > index 00000000000..fc1e2e742a1
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/debug/pr101533.C
> > @@ -0,0 +1,11 @@
> > +// { dg-do compile }
> > +// { dg-options "-g" }
> > +
> > +template <typename> class T
> > +{
> > + typedef struct {} a __attribute__((aligned));
> > +};
> > +void f ()
> > +{
> > + T<int>();
> > +}
>
>
>
--
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)