https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122521
--- Comment #40 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Mikael Morin <[email protected]>: https://gcc.gnu.org/g:cbaf11be6911a97857010b995a04788a454d91f5 commit r17-6975-gcbaf11be6911a97857010b995a04788a454d91f5 Author: Mikael Morin <[email protected]> Date: Tue Dec 1 11:54:32 2026 +0100 fortran: array descriptor: Add a check for class container type [PR122521] In the function generating descriptor initialization from a scalar polymorphic reference, the data descriptor component is initialized with the _data component of the class container reference provided as input. Add a check that the input reference really has class container type before adding a subreference to the _data component. The input used to not have class container type sometimes, but as that was nowhere checked, a subcomponent reference was generated nevertheless to the first field of the polymorphic content. With polymorphic scalar coarrays, for example, the input reference matches the class->_data.data pattern, i.e. it already includes a reference to the _data field of the class container and to the data field of the array descriptor, and there is no need to add any subcomponent. The problem fixed here is less serious than it looks. A spurious reference to the first component, that has offset 0, doesn't change the resulting address. But if the type has no component at all, as in the testcase, it can cause the compilation to abort. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.cc: (gfc_set_descriptor_from_scalar_class): Don't add a reference to the _data component if the base reference hasn't class container type. gcc/testsuite/ChangeLog: * gfortran.dg/assumed_rank_26.f90: New test.
