https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105117
Bug ID: 105117 Summary: automatic deallocation of objects in procedures with heap arrays Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: a.shahmoradi at gmail dot com Target Milestone: --- The following code yields a runtime error when compiled with heap arrays option `gfortran -fmax-stack-var-size=10 main.f90 -o`, ``` call testAutoDealloc call testAutoDealloc contains subroutine testAutoDealloc real, allocatable :: temp(:) allocate(temp(200)) !deallocate(temp) end end ``` The problem is that `temp` is not automatically deallocated when the program returns the control to the main scoping unit. To the best of my knowledge, this appears to be a bug. Allocatable should be automatically deallocated when it is out of scope, regardless of heap vs. stack usage. Intel ifort has no issues with it. The code can be tested here: https://godbolt.org/z/9z48Tze8c