Fortran LEN of a PDT character array component is scalar [PR128936].
Fixes incorrect handling of character array component lengths in Fortran's Parameterized Derived Types (PDTs).
This change corrects how the Fortran compiler handles the LEN of character array components within Parameterized Derived Types (PDTs). The gfc_simplify_len function previously mishandled references to length parameters for such components, dropping array references and incorrect KIND values, leading to ICEs and incorrect type assignments. The fix preserves base object array references, resolves new references to scalar type parameter inquiries, and ensures correct KIND conversion, while also fixing a double-free bug in reset_array_ref_to_scalar.
In Details
In gfc_simplify_len within simplify.cc, the compiler mishandled LEN inquiries on character array components of Parameterized Derived Types (PDTs) when the component's length was a LEN parameter. It incorrectly replaced LEN(x%ch) with a reference to the parameter, dropped the array rank of the component, and lost the KIND= specifier. This resulted in ICEs and incorrect type handling. This patch corrects gfc_simplify_len to retain base object array references, resolve the LEN inquiry correctly as a scalar type parameter inquiry, and convert it to the requested KIND. Additional…
- PDT
- Parameterized Derived Type. In Fortran, a derived type whose definition includes parameters that must be specified when the type is declared, often used for generic data structures with configurable properties like length or kind.
- LEN parameter
- A parameter, typically used in Fortran's derived types, that specifies the length of a character component.
- KIND
- In Fortran, specifies the numerical precision or representation of intrinsic types (like INTEGER, REAL, CHARACTER). Different KIND values correspond to different storage sizes and precision levels.
- ICE
- Internal Compiler Error. An unrecoverable error encountered by the compiler during compilation, typically indicating a bug in the compiler itself.