Fortran: Fixed automatic deallocation with derived type IO.
Corrects an issue in Fortran derived type IO that prevented automatic deallocation of local variables by adjusting the function specification.
This commit resolves an issue in the Fortran compiler related to derived type input/output (DTIO). The compiler was incorrectly forcing allocatable instances of derived types used in IO operations to be static, preventing automatic deallocation of local variables. This was due to a misconfiguration in the function specification for _gfortran_transfer_derived, where the IO variable was incorrectly declared as read-only. Changing the specification to indicate write access resolves the problem and allows for proper automatic deallocation. A new test case verifies the fix.
In Details
The gfc_finish_var_decl function in trans-decl.cc was incorrectly forcing variables with DTIO to be static. This commit removes that code. The underlying cause was the fnspec attribute of _gfortran_transfer_derived in trans-io.cc indicating read-only access ('r') instead of write access ('w'). This is corrected, enabling proper deallocation. The new test gfortran.dg/dtio_37.f90 checks the fix.
For Context
In Fortran, derived types allow users to create custom data structures. Derived type input/output (DTIO) allows these custom types to be read from and written to files. This commit fixes a bug that prevented local variables of derived types used in IO from being automatically deallocated when they were no longer needed, which could lead to memory leaks. The fix ensures that these variables are properly deallocated, improving program stability and resource management.