The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:1da1aa07b7b7b529770015c279e9faad3292c696

commit r17-5065-g1da1aa07b7b7b529770015c279e9faad3292c696
Author: Jerry DeLisle <[email protected]>
Date:   Wed Jun 10 08:36:59 2026 -0700

fortran: [PR125721] Fix ICE for a class pointer component in a structure constructor

Thanks for quick review.
On 10/11/26 3:15 AM, Mikael Morin wrote:
Le 10/10/2026 à 21:57, Jerry DeLisle a écrit :
See attached patch. A structure constructor that associates a CLASS
pointer component with a non-class target ICEs in fold_convert_loc for
a scalar component and segfaults in gfc_conv_scalarized_array_ref for
an array component. The POINTER attribute is on CLASS_DATA (cm), not on
cm, so gfc_trans_subcomponent_assign never takes a pointer branch and
treats the value as a derived-type or scalar copy. The patch adds a
branch that points _data at the target, through gfc_conv_expr_descriptor
with direct_byref for an array, sets _vptr from the target's vtab and,
for an unlimited polymorphic component, sets _len to the character
length or zero. A polymorphic value still takes the existing path.

The fix is the new CLASS pointer branch in gfc_trans_subcomponent_assign
in trans-expr.cc. structure_constructor_20.f90 covers scalar components,
including a CHARACTER target for class(*). structure_constructor_21.f90
covers array components and is adapted from test 0555_0400.f90 of the
Fujitsu compiler test suite.

Regression tested on x86_64.

OK for mainline?

Regards,

Jerry

---

fortran: [PR125721] Fix ICE for a class pointer component in a structure constructor

In a structure constructor, associate a scalar or array CLASS pointer
component with a non-class target: set _data, _vptr and, for an
unlimited polymorphic component, _len.

Assisted-by: Claude Opus 5.5

    PR fortran/125721

gcc/fortran/ChangeLog:

    * trans-expr.cc (gfc_trans_subcomponent_assign): Handle a CLASS
    pointer component with a non-class target.

gcc/testsuite/ChangeLog:

    * gfortran.dg/structure_constructor_20.f90: New test.
    * gfortran.dg/structure_constructor_21.f90: New test.
OK.

Reply via email to