On Mon, Jun 17, 2024 at 02:42:05PM +0200, Richard Biener wrote:
> > > > I am trying to understand what check_qualified_type
> > > > does exactly. The direct comparison of TYPE_NAMES seems incorrect
> > > > for C and its use is c_update_type_canonical then causes
> > > > PR114930 and PR115502. In the later function I think
> > > > it is not really needed and I guess one could simply remove
> > > > it, but I wonder if it works incorrectly in other casesĀ
> > > > too?
> > >
> > > TYPE_NAMES is compared because IIRC typedefs are recorded as variants
> > > and 'const T' isn't the same as 'const int' with typedef int T.
> >
> > so if it is intentional that it differentiates between
> >
> > struct foo
> >
> > and
> >
> > typedef struct foo bar
> >
> > then I will change c_update_type_canonical to not use it,
> > because both types should have the same TYPE_CANONICAL
>
> The check is supposed to differentiate between variants and all variants
> have the same TYPE_CANONICAL so I'm not sure why you considered using
> this function for canonical type compute?
I've done that and that was because build_qualified_type uses that
predicate, where qualified types created by build_qualified_type have
as TYPE_CANONICAL the qualified type of the main variant of the canonical
type, while in all other cases TYPE_CANONICAL is just the main variant of
the type.
Guess we could also just do
if (TYPE_QUALS (x) == TYPE_QUALS (t))
TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
else if (TYPE_CANONICAL (t) != t
|| TYPE_QUALS (x) != TYPE_QUALS (TYPE_CANONICAL (t)))
TYPE_CANONICAL (x)
= build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
else
TYPE_CANONICAL (x) = x;
or so.
Jakub