fortran: Fix ICE sizing CLASS component from derived value
Corrects an ICE in Fortran when sizing CLASS components of structures from derived types.
GCC Fortran encountered an Internal Compiler Error (ICE) when allocating a CLASS component of a structure constructor from a non-polymorphic derived-type value. The problem occurred because the allocation function was incorrectly passed the type’s own symbol instead of the correct type node for sizing. This patch ensures that gfc_typenode_for_spec is used for derived types as well, resolving the ICE and enabling correct sizing.
In Details
In trans-expr.cc, the alloc_scalar_allocatable_subcomponent function caused an ICE when allocating a CLASS component from a derived-type value. It incorrectly passed the type's symbol to gfc_get_symbol_decl to obtain size information. This commit modifies the function to use gfc_typenode_for_spec for BT_DERIVED types, consistent with how it handles other types, thus obtaining the correct type information for sizing.
- CLASS component
- In Fortran, a component of a derived type that can hold values of different intrinsic or derived types at runtime, determined by polymorphism or type-bound procedures.
- derived type
- A user-defined data type in Fortran, similar to a struct or class in other languages, composed of components of intrinsic or other derived types.
- structure constructor
- In Fortran, a mechanism to create an instance of a derived type by specifying the values for its components in order.
- ICE
- Internal Compiler Error. An unrecoverable error that occurs within the compiler itself, typically indicating a bug in the compiler's logic.
- gfc_typenode_for_spec
- A Fortran compiler internal function, likely used to obtain a representation of a type's specification for further processing, such as size calculation or type checking.