Fortran: Fix parameterized derived type errors
Corrects an error in Fortran's parameterized derived type handling by ensuring allocation compatibility.
This commit addresses a bug in the Fortran compiler’s handling of parameterized derived types (PDTs) by fixing an issue in the gfc_trans_deferred_vars function. It ensures that the PDT component allocation function (gfc_allocate_pdt_comp) is only called when the symbol associated with the component has a valid parameter list. This prevents erroneous calls and subsequent miscompilations for certain PDT instantiations.
In Details
This patch for PR82173 targets trans-decl.cc and modifies gfc_trans_deferred_vars. The core issue was calling gfc_allocate_pdt_comp when the symbol lacked a param_list. This commit adds a check to ensure sym->param_list is not NULL before proceeding with the allocation, preventing a potential crash or incorrect code generation for PDTs where the component's parameter list is not yet established or is absent.
- Parameterized Derived Type (PDT)
- A derived type in Fortran whose components or other attributes can be specified by parameters at the time of type instantiation, similar to templates in C++ or generic types in other languages.
- Fortran gfc
- The internal representation and processing framework used by the GNU Fortran compiler (gfortran) to manage Fortran source code during compilation.
- symbol
- In a compiler's internal representation, a symbol typically represents a named entity in the source code, such as a variable, function, or type. It holds information about that entity.
- param_list
- Likely refers to a data structure within the Fortran compiler's internal representation that holds the parameters associated with a parameterized derived type.