https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97592
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Mikael Morin <[email protected]>: https://gcc.gnu.org/g:6658c2347d4a88d82e80f44a450b14dc7287bcef commit r17-2111-g6658c2347d4a88d82e80f44a450b14dc7287bcef Author: Mikael Morin <[email protected]> Date: Fri Jul 3 11:16:04 2026 +0200 fortran: Don't reuse original descriptors for packed arrays [PR125998] Don't try to reuse the original descriptor when creating a descriptor for packed data in gfc_conv_array_parameter. For a non-transposed array (anything but TRANSPOSE(VAR)) the original descriptor was reused, and only the data was reset to the result of packing. This is wrong because the original descriptor can be non-contiguous, it can't be correct as the descriptor of packed data. In the testcase, a dummy array associated with a transposed array actual argument matches this case. Reusing the descriptor in that case would cause the packed data to be used transposed, that is not in the normal array element order. This change removes this case to always fallback to what was previously the transposed case (see next). For the transposed case (TRANSPOSE(VAR)), the full dimensions of the original untransposed descriptor were reused (in other words, the dimensions of VAR). This is wrong because packing doesn't change the shape, so the packed array should have the same bounds as the bounds of TRANSPOSE(VAR), not the same bounds as VAR. Reusing the strides of an unpacked array for a packed array doesn't seem right either. This change uses matching dimensions when copying from the original descriptor, and only copies the lbound and ubound. The strides are recalculated. And then the offset is recalculated as well (even though I couldn't find a testcase where it made a difference). PR fortran/97592 PR fortran/125998 gcc/fortran/ChangeLog: * trans-array.cc (gfc_conv_array_parameter): Always create a new descriptor. Copy lbound and ubound from the original descriptor using matching dimension indexes. Recalculate stride and offset. gcc/testsuite/ChangeLog: * gfortran.dg/contiguous_17.f90: New test.
