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

Jerry D <[email protected]> Wed, 24 Jun 2026 10:39:41 -0700
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:d145946aa4e65dd0f5afb2d29564cb1514f28358

commit r17-1814-gd145946aa4e65dd0f5afb2d29564cb1514f28358
Author: Jerry DeLisle <[email protected]>
Date:   Tue Jun 23 12:56:24 2026 -0700

     fortran: [PR125761] Unlimited-poly character array section base

On 6/24/26 10:07 AM, Jerry D wrote:
> On 6/24/26 2:57 AM, Mikael Morin wrote:
>> 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.
>>
>>
> 
> Thanks for catching that, I was focused on other work and forgot to delete it.
> 
> It is removed and all of the gfortran.dg passes. I am rebasing on the remote 
> master and doing a complete rebuild and rerun for regressions. If all passes, I 
> will push to mainline.
> 
> Thanks for you reviews and feedback.
> 
> Best regards,
> 
> Jerry