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

Jerry DeLisle jvdelisle2@gmail.com
Sat Oct 10 19:57:38 GMT 2026


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PR125721-class-pointer-component-ctor.patch
Type: text/x-patch
Size: 6371 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20261010/11c52781/attachment-0001.bin>


More information about the Gcc-patches mailing list