Fortran parenthesized allocatable components caused memory leaks
Fixes memory leaks in Fortran when using parenthesized types with allocatable components as arguments or selectors.
A bug in Fortran’s type handling led to memory leaks when using parenthesized types with allocatable components. These types, when used as actual arguments or ASSOCIATE selectors, caused a deep copy into new storage that was never freed. This change ensures that TYPE temporaries are passed without copying or freeing their components, and that CLASS temporaries are finalized correctly, preventing the leaks.
In Details
This commit addresses a memory leak in the Fortran frontend related to temporary variables derived from types with allocatable components. When such temporaries are created (e.g., as procedure call arguments or ASSOCIATE selectors), incorrect handling of their components leads to unreleased memory. The fix modifies gfc_conv_expr_descriptor and introduces parenthesized_variable to manage temporary finalization and component sharing, preventing leaks for both CLASS and TYPE temporaries.
- allocatable component
- In Fortran, a component of a derived type that can be dynamically allocated and deallocated using the
ALLOCATEandDEALLOCATEstatements. - ASSOCIATE
- A Fortran construct that allows a variable or expression to be referred to by a different name within a block of code, simplifying complex or lengthy names.
- TYPE temporary
- An intermediate variable of a derived type created by the compiler during expression evaluation or argument passing, which may be optimized away or have its lifetime managed.
- CLASS temporary
- Similar to a TYPE temporary, but specifically for variables of polymorphic types (declared with
CLASS(*)orCLASS(type)in Fortran), which can hold objects of different specific types at runtime. - vtable
- Virtual Method Table. A table used in languages with dynamic dispatch (like C++ or polymorphic Fortran) that stores pointers to virtual functions. An object typically contains a pointer to its class's vtable.