On Wed, Jun 19, 2024 at 09:36:40AM +0200, Richard Biener wrote:
> > TYPE_CANONICAL (x)
> > = build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
>
> That looks indeed weird. What are the constraints on 't' for
> c_update_type_canonical? If it is TYPE_STRUCTURAL_EQUALITY_P
> the above will segfault.
>
> The docs of the function says
>
> /* Recompute TYPE_CANONICAL for variants of the type including qualified
> versions of the type and related pointer types after an aggregate type
> has been finalized.
>
> but it seems to also possibly update the main variants canonical type.
> But the main variants canonical type should be the canonical type of
> all other variants, so I would expect the function to determine
> the main variant, possibly update (why?) it's canonical type and
> then assign that to all variant types.
The function is supposed to be called on previously
TYPE_STRUCTURAL_EQUALITY_P main variant on which the FE set
TYPE_CANONICAL to non-NULL:
gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT);
if (*e)
TYPE_CANONICAL (t) = *e;
else
{
TYPE_CANONICAL (t) = t;
*e = t;
}
c_update_type_canonical (t);
and the function should propagate that canonical type or canonical types
derived from that also to its variants (qualified or unqualified) and
pointers to those as long as the variants/pointers are still
TYPE_STRUCTURAL_EQUALITY_P before the change.
Jakub