Re: [PATCH] Fortran: Fix PR125761 Wrong code: array section of an unlimited-polymorphic CHARACTER array

Mikael Morin <[email protected]> Wed, 24 Jun 2026 11:57:53 +0200
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Hello,

Le 23/06/2026 à 23:24, Jerry D a écrit :
> diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
> index adf392cec6f..c10484ff636 100644
> --- a/gcc/fortran/trans.cc
> +++ b/gcc/fortran/trans.cc
> @@ -524,8 +524,13 @@ gfc_build_array_ref (tree base, tree offset, tree decl,
>        span = gfc_vptr_size_get (vptr);
>  
>        /* Check if this is an unlimited polymorphic object carrying a character
> -	 payload. In this case, the 'len' field is non-zero.  */
> -      if (decl && GFC_CLASS_TYPE_P (TREE_TYPE (decl)))
> +	 payload. In this case, the 'len' field is non-zero.  The class
> +	 container type does not always carry GFC_CLASS_TYPE_P, but its
> +	 canonical type does.  */
> +      if (decl
> +	  && (GFC_CLASS_TYPE_P (TREE_TYPE (decl))
> +	      || (TYPE_CANONICAL (TREE_TYPE (decl))
> +		  && GFC_CLASS_TYPE_P (TYPE_CANONICAL (TREE_TYPE (decl))))))
>  	span = gfc_resize_class_size_with_len (NULL, decl, span);
>      }
>    else if (decl)
this hunk isn't needed any more, I think, or is it?  It was the very 
purpose of the GFC_CLASS_TYPE_P business to drop this change.

Otherwise OK.

Thanks.