On Mon, Jun 17, 2024 at 03:53:41PM +0200, Martin Uecker wrote: > > If c_update_type_canonical is only ever called for the main variants of the > > type and they always have !TYPE_QUALS (t), then yes. > > But if we rely on that, perhaps we should gcc_checking_assert that. > > So > > gcc_checking_assert (t == TYPE_MAIN_VARIANT (t) && !TYPE_QUALS (t)); > > or something similar at the start of the function. > > It calls itself recursively on pointers to the type. But to > me the third branch looks dead in any case, because the first > two cover all possibilities.
Yes, but the pointers built by build_pointer_type should still be hopefully the unqualified versions, if one wants a qualified pointer, that would be build_qualified_type (build_pointer_type (...), ...) The checks cover all the possibilities only if the canonical type has the same quals as t. > > Then we could also change the > > for (tree x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) > > to > > for (tree x = t; x; x = TYPE_NEXT_VARIANT (x)) > > and > > if (TYPE_QUALS (x) == TYPE_QUALS (t)) > > ... > > to > > if (!TYPE_QUALS (x)) > > TYPE_CANONICAL (x) = TYPE_CANONICAL (t); > > else > > build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x)); > > Jakub