------- Comment #2 from burnus at gcc dot gnu dot org 2009-07-20 08:32 ------- Further simplified test below. Valgrind shows first: ==29083== Conditional jump or move depends on uninitialised value(s) ==29083== at 0x4007E4: MAIN__ (aa.f90:12)
The problem is that t2's y is unallocated, which is valid but confuses the algorithm. For the following program, gfortran generates: fun () { (void) 0; } which is then used as: q = fun (); if (D.1570.y.data != 0B) __builtin_free (D.1570.y.data); q.y.data = 0B; I think the proper code would be: fun () { struct t2 q = {}; return q; } module mod_all implicit none type t2 integer, allocatable :: y(:) end type t2 contains pure function fun() result(q) type(t2) :: q ! Returning q - consisting only of one deallocated compound end function fun end module mod_all program main use mod_all implicit none type(t2) :: q q = fun() end program main -- burnus at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Known to fail| |4.5.0 4.4.0 4.3.3 4.2.1 Summary|Double free or corruption |Invalid code when returning |with derived types with |unallocated component of |allocatable components |derived type http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40796