On Wed, 19 Jun 2024, Jakub Jelinek wrote:

> On Wed, Jun 19, 2024 at 08:04:55AM +0200, Richard Biener wrote:
> > >> Note a canonical type should always be unqualified (for
> > >> classical qualifiers, not address space or atomic qualification)
> > > 
> > > The logic in build_qualified_type is the same as in this patch,
> > > it constructs TYPE_CANONICAL with qualifiers.  Or what am I
> > > missing?
> > 
> > Nothing if you chose to do TYPE_QUALS (canonical) by copy-pasting.
> 
> As I mentioned earlier, I'd prefer the following version and I have
> already tested it on the testcases (note, some changes to the tests,
> e.g. using lto effective target), just haven't bootstrapped/regtested it
> fully yet.

LGTM, but I'd defer to a FE maintainer for approval.

Richard.

> gcc/c/
>       * c-decl.cc (c_update_type_canonical): Assert t is main variant
>       with 0 TYPE_QUALS.  Simplify and don't use check_qualified_type.
> gcc/testsuite/
>       * gcc.dg/pr114930.c: New test.
>       * gcc.dg/pr115502.c: New test.
> 
> --- gcc/c/c-decl.cc.jj        2024-06-07 12:17:09.582969919 +0200
> +++ gcc/c/c-decl.cc   2024-06-18 21:30:22.881904947 +0200
> @@ -9367,18 +9367,16 @@ is_flexible_array_member_p (bool is_last
>  static void
>  c_update_type_canonical (tree t)
>  {
> -  for (tree x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
> +  gcc_checking_assert (TYPE_MAIN_VARIANT (t) == t && !TYPE_QUALS (t));
> +  for (tree x = t; x; x = TYPE_NEXT_VARIANT (x))
>      {
>        if (x != t && TYPE_STRUCTURAL_EQUALITY_P (x))
>       {
> -       if (TYPE_QUALS (x) == TYPE_QUALS (t))
> +       if (!TYPE_QUALS (x))
>           TYPE_CANONICAL (x) = TYPE_CANONICAL (t);
> -       else if (TYPE_CANONICAL (t) != t
> -                || check_qualified_type (x, t, TYPE_QUALS (x)))
> +       else
>           TYPE_CANONICAL (x)
>             = build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x));
> -       else
> -         TYPE_CANONICAL (x) = x;
>       }
>        else if (x != t)
>       continue;
> --- gcc/testsuite/gcc.dg/pr114930.c.jj        2024-06-18 21:27:53.782729543 
> +0200
> +++ gcc/testsuite/gcc.dg/pr114930.c   2024-06-18 21:27:53.782729543 +0200
> @@ -0,0 +1,9 @@
> +/* PR c/114930 */
> +/* { dg-do compile { target lto } } */
> +/* { dg-options "-std=c23 -flto" } */
> +
> +typedef struct WebPPicture WebPPicture;
> +typedef int (*WebPProgressHook)(const WebPPicture *);
> +WebPProgressHook progress_hook;
> +struct WebPPicture {
> +} WebPGetColorPalette(const struct WebPPicture *);
> --- gcc/testsuite/gcc.dg/pr115502.c.jj        2024-06-18 21:27:53.793729408 
> +0200
> +++ gcc/testsuite/gcc.dg/pr115502.c   2024-06-18 21:27:53.793729408 +0200
> @@ -0,0 +1,9 @@
> +/* PR c/115502 */
> +/* { dg-do compile { target lto } } */
> +/* { dg-options "-std=c23 -flto" } */
> +
> +typedef struct _OSet OSet;
> +typedef OSet AvlTree;
> +void vgPlain_OSetGen_Lookup(const OSet *);
> +struct _OSet {};
> +void vgPlain_OSetGen_Lookup(const AvlTree *);
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to