https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127613
--- Comment #6 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:78cfe216a8e042830325df586eb179e18cd3d37f commit r17-5755-g78cfe216a8e042830325df586eb179e18cd3d37f Author: Mikael Morin <[email protected]> Date: Fri Oct 30 11:14:09 2026 +0100 fortran: Fix simply contiguous for polymorphic arrays [PR127613] In the implementation of the simply contiguous predicate, take into account class containers when identifying non-contiguous pointers, assumed-rank or assumed-shape dummies. The implementation was picking the last component reference in the chain to return false if it had the pointer but not the contiguous attribute. This was causing the predicate to return false for a polymorphic contiguous array, because the last component is the _data component of the class container. It has the pointer attribute for a non-allocatable dummy or a pointer, and it hasn't the contiguous attribute which is stored in the parent entity, that is at the class container level. Fixing this requires keeping at the same time access to the contiguous attribute, the pointer attribute and the array type. So this change omits advancing the last component reference to the next during the walk, if the next is the _data component of a class container. Then the rest just needs to discriminate the attribute and array spec query between polymorphic and non-polymorphic references; for the pointer attribute we can just use the IS_POINTER macro. Associate names are explicitly excluded at that point so that we have the opportunity to forward the simply contiguous query to the associate target for them. PR fortran/127613 gcc/fortran/ChangeLog: * expr.cc (gfc_is_simply_contiguous): Track the current type during the data reference walk and only keep component references that are not the _data component of a class container. Query the array type on the _data component of the class container for polymorphic variables. gcc/testsuite/ChangeLog: * gfortran.dg/contiguous_19.f90: New test.
