Copy derived-type and CLASS actuals for VALUE dummies
Ensures correct argument passing for Fortran VALUE dummy arguments of derived types and CLASS types, handling allocatable components and sharing semantics.
This change corrects the handling of Fortran VALUE dummy arguments, particularly for derived types with allocatable components and CLASS actual arguments. According to the Fortran 2023 standard, VALUE arguments are passed by copy. Previously, gfortran incorrectly shared data for derived types with allocatable components and handled CLASS dummies improperly. This patch ensures that derived types with allocatable components are passed by reference to a copy, allowing the callee to deallocate components. It also ensures that CLASS dummies receive a copy of the data through the vtable, handling intrinsic actual arguments correctly.
In Details
The Fortran VALUE dummy argument passing mechanism has been updated to comply with F2023 15.5.2.4. For derived types with allocatable components, the actual argument is now passed by reference to a copy, rather than by value which shared the component data. This is because the caller frees the components of the copy, and the callee must deallocate its own copy. The gfc_value_dummy_passed_byref function now dictates this behavior. For scalar CLASS dummies, the actual argument's data is copied via the vtable. Function results or constructor expressions, which are anonymous objects, are not co…
- Fortran
- A high-level programming language primarily used for scientific and numerical computation. GCC includes a Fortran compiler (gfortran).
- VALUE dummy argument
- In Fortran, a dummy procedure argument declared with the VALUE attribute. The actual argument corresponding to a VALUE dummy is passed by copying its value, rather than by reference.
- derived type
- A user-defined data type in Fortran that can aggregate variables of different types and ranks, similar to structs in C or classes in C++.
- allocatable components
- Components within a derived type that are declared with the ALLOCATABLE attribute. These components can be dynamically allocated and deallocated during program execution.
- CLASS dummy argument
- A dummy procedure argument in Fortran that is declared with the CLASS(*) type. It can receive actual arguments of any declared type (polymorphic).
- vtable
- Virtual Method Table. In object-oriented programming, a table used to implement dynamic dispatch. In gfortran, it can be used for handling polymorphic (CLASS) arguments.
- deallocate
- A Fortran statement used to release memory that was previously allocated for ALLOCATABLE or POINTER variables.