https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100155
Paul Thomas <pault at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org CC| |pault at gcc dot gnu.org --- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> --- Created attachment 60425 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60425&action=edit This patch fixes the problem but needs to be completely refactored Fixing the original testcase was reasobly straightforward. However, once allocatable components were added, it leaked memory. The last, big chunk escapes the code, somewhere downstream, that generates unnecessary temporaries and copies in the post block, thereby causing the memory leaks. I am not sure that this is really a regression, although I will try reverting the patch that is fingered, but it is as well that it is marked as such because I would have missed it otherwise. PR105168 is also fixed with the patch, up to a residual memory leak with allocatable components. The testcase below compiles and runs correctly. Paul ! { dg-do run } ! Test the fix for PR100155 in which the parentheses caused an ICE ! in evaluation the specification expression for 'z'. Note that the ! recursive attribute is not a factor in the ICE (see PR105168). ! Contributed by Gerhard Steinmetz <gs...@t-online.de> ! module m1 type t integer, allocatable :: i end type integer :: ctr = 0, vals = 0 integer, parameter :: no_calls = 6 contains recursive function f(x) result(z) class(t) :: x(:) type(t) :: z(size(x)+1) class(t), allocatable :: a(:) type(t), allocatable :: b(:) ctr = ctr + 1 allocate (t :: a(1)) a(1)%i = ctr if (ctr <= no_calls - 1) then b = f((a)) ! <== parentheses else allocate (b(a(1)%i)) b(1)%i = ctr end if vals = vals + b(1)%i z(1) = t(b(1)%i) end end module m1 use m1 type (t) :: dummy(1) type(t), allocatable :: res(:) dummy = t(1) res = f (dummy); if (ctr /= no_calls) stop 1 if (vals /= (2 * sum ([(i, i = 1, no_calls)]) - no_calls)) stop 2 if (size (res) /= 2) stop 3 deallocate (res) deallocate (dummy(1)%i) end