https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125761
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- 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 When a CLASS(*) array section carrying a CHARACTER payload is passed as the base of an array reference, build_array_ref and gfc_build_array_ref computed the element span from the dynamic type's vptr size alone, ignoring the unlimited-polymorphic object's _len field. For a deferred-length character payload this gave the wrong element size, so the section's data pointer was offset incorrectly by the lower bound, producing wrong code (no ICE needed to reproduce: a section of a CLASS(*) character array passed to a procedure reads from the wrong address). PR fortran/125761 gcc/fortran/ChangeLog: * trans-array.cc (build_array_ref): When the descriptor's canonical type is a class type, pass the class container as 'decl' to gfc_build_array_ref for genuine array element references (rank > 0), so the element size can be corrected for an unlimited-polymorphic character payload. * trans-types.cc (gfc_typenode_for_spec): Move setting the GFC_CLASS_TYPE_P bit to.. (gfc_get_derived_type): .. and use attr.is_class. (gfc_get_derived_type): Move setting the GFC_CLASS_TYPE_P bit as the last step before returning the derived->backend_decl if the derived->attr.is_class is true. gcc/testsuite/ChangeLog: * gfortran.dg/select_type_53.f90: New test.
