Thanks Paul, The master branch has been updated by Jerry DeLisle <[email protected]>:
https://gcc.gnu.org/g:0c3daf65d25db056f27981e309f574fae1ce6b9c commit r17-6605-g0c3daf65d25db056f27981e309f574fae1ce6b9c On 11/23/26 2:33 AM, Paul Richard Thomas wrote:
Hi Jerry, This patch is fine by me - OK for mainline. I have a minor niggle concerning the terminology used in the patch: "LEN-parameter string component," is surely better replaced by "parameterized string" or "PDT string"? Thanks for the patch! Paul On Sun, 22 Nov 2026 at 02:18, Jerry DeLisle <[email protected]> wrote:See attached patch. For a CHARACTER array component whose length is a LEN parameter, gfc_simplify_len builds its result from a copy of the argument with all references dropped and the type parameter added as a component reference. The copy keeps the rank and shape of x%ch, and an array reference on the base object, as in y(2)%ch, is lost. The patch keeps the leading array references, runs gfc_resolve_ref on the result, which makes it a scalar type parameter inquiry through reset_array_ref_to_scalar, and converts it to the KIND= kind. That function left freed end and stride pointers in a section, which y(2:3)%n already hits on trunk as an ICE in free_expr0. The fix is in gfc_simplify_len in simplify.cc, plus the clearing of the freed pointers in reset_array_ref_to_scalar in resolve.cc; the rest is the new test. Regression tested on x86_64. OK for mainline? Regards, Jerry --- fortran: [PR128936] LEN of a PDT character array component is scalar For a CHARACTER array component whose length is a LEN parameter, gfc_simplify_len replaced LEN (x%ch) by a reference to the parameter but kept the rank of the component, dropped the array reference of the base object and ignored KIND=. An assignment of the result was rejected, LEN (y(2)%ch) hit an ICE, and KIND=8 gave a default integer. Keep the array references of the base, resolve the new reference so that it becomes a scalar type parameter inquiry, and convert it to the requested kind. reset_array_ref_to_scalar freed the end and stride of a section without clearing them, so y(2:3)%n freed them twice; clear them. Assisted-by: Claude Opus 5.5 PR fortran/128936 gcc/fortran/ChangeLog: * resolve.cc (reset_array_ref_to_scalar): Clear the end and stride after freeing them. * simplify.cc (gfc_simplify_len): Keep the array references of the base object for a LEN-parameter string component, resolve the result and convert it to the requested kind. gcc/testsuite/ChangeLog: * gfortran.dg/pdt_99.f90: New test.
