[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952
--- Comment #6 from GCC Commits ---
The releases/gcc-15 branch has been updated by Harald Anlauf
:
https://gcc.gnu.org/g:2acc6fd276b48579f712d1016519c0b2382a6aa6
commit r15-11177-g2acc6fd276b48579f712d1016519c0b2382a6aa6
Author: Harald Anlauf
Date: Thu May 7 22:34:52 2026 +0200
Fortran: fix automatic deallocation with derived type IO
[PR111952,PR125059]
The implementation of derived type IO wrongly forced allocatable instances
of the DT as static, which prevented automatic deallocation of local
variables. The motivation was an attempt to prevent optimizations leading
to certain testcase failures. Howver, the underlying reason of the problem
was a wrong fnspec of _gfortran_transfer_derived that declared the IO
variable as being only read ('r'). Declare the corresponding parameter as
being written ('w').
PR fortran/111952
PR fortran/125059
gcc/fortran/ChangeLog:
* trans-decl.cc (gfc_finish_var_decl): Remove bogus code forcing
a DT variable with DTIO as static.
* trans-io.cc (gfc_build_io_library_fndecls): Fix fnspec attribute.
gcc/testsuite/ChangeLog:
* gfortran.dg/dtio_37.f90: New test.
(cherry picked from commit 1904b9207203bbe45d6ce6a472d6a0c7e1bbd873)
[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952
--- Comment #5 from GCC Commits ---
The releases/gcc-16 branch has been updated by Harald Anlauf
:
https://gcc.gnu.org/g:ef03d3cfb45e0d75c137223c805ad75a3b7e319d
commit r16-8905-gef03d3cfb45e0d75c137223c805ad75a3b7e319d
Author: Harald Anlauf
Date: Thu May 7 22:34:52 2026 +0200
Fortran: fix automatic deallocation with derived type IO
[PR111952,PR125059]
The implementation of derived type IO wrongly forced allocatable instances
of the DT as static, which prevented automatic deallocation of local
variables. The motivation was an attempt to prevent optimizations leading
to certain testcase failures. Howver, the underlying reason of the problem
was a wrong fnspec of _gfortran_transfer_derived that declared the IO
variable as being only read ('r'). Declare the corresponding parameter as
being written ('w').
PR fortran/111952
PR fortran/125059
gcc/fortran/ChangeLog:
* trans-decl.cc (gfc_finish_var_decl): Remove bogus code forcing
a DT variable with DTIO as static.
* trans-io.cc (gfc_build_io_library_fndecls): Fix fnspec attribute.
gcc/testsuite/ChangeLog:
* gfortran.dg/dtio_37.f90: New test.
(cherry picked from commit 1904b9207203bbe45d6ce6a472d6a0c7e1bbd873)
[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952
--- Comment #4 from GCC Commits ---
The master branch has been updated by Harald Anlauf :
https://gcc.gnu.org/g:1904b9207203bbe45d6ce6a472d6a0c7e1bbd873
commit r17-410-g1904b9207203bbe45d6ce6a472d6a0c7e1bbd873
Author: Harald Anlauf
Date: Thu May 7 22:34:52 2026 +0200
Fortran: fix automatic deallocation with derived type IO
[PR111952,PR125059]
The implementation of derived type IO wrongly forced allocatable instances
of the DT as static, which prevented automatic deallocation of local
variables. The motivation was an attempt to prevent optimizations leading
to certain testcase failures. Howver, the underlying reason of the problem
was a wrong fnspec of _gfortran_transfer_derived that declared the IO
variable as being only read ('r'). Declare the corresponding parameter as
being written ('w').
PR fortran/111952
PR fortran/125059
gcc/fortran/ChangeLog:
* trans-decl.cc (gfc_finish_var_decl): Remove bogus code forcing
a DT variable with DTIO as static.
* trans-io.cc (gfc_build_io_library_fndecls): Fix fnspec attribute.
gcc/testsuite/ChangeLog:
* gfortran.dg/dtio_37.f90: New test.
[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952 anlauf at gcc dot gnu.org changed: What|Removed |Added Resolution|--- |DUPLICATE Status|NEW |RESOLVED CC||anlauf at gcc dot gnu.org --- Comment #3 from anlauf at gcc dot gnu.org --- Dup. *** This bug has been marked as a duplicate of bug 125059 ***
[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952 Jerry DeLisle changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed||2025-12-04 --- Comment #2 from Jerry DeLisle --- (In reply to Jerry DeLisle from comment #1) > What is the expected behavior? > > $ ./a.out > At line 22 of file allocator.f90 > Fortran runtime error: Attempting to allocate already allocated variable 'x' > > Is it expected that the variable is deallocated upon exit from the > subroutine? OH I see now. If I comment out all the DTIO related lines, the error goes away. I should note that flang accepts it all as you expected. The definitions of DTIO procedures should not affect automatic deallocation.
[Bug fortran/111952] Allocatable of derived type with DTIO is not deallocated going out of scope
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111952 Jerry DeLisle changed: What|Removed |Added CC||jvdelisle at gcc dot gnu.org --- Comment #1 from Jerry DeLisle --- What is the expected behavior? $ ./a.out At line 22 of file allocator.f90 Fortran runtime error: Attempting to allocate already allocated variable 'x' Is it expected that the variable is deallocated upon exit from the subroutine?
