https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114612

Dominik Gronkiewicz <gronki at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gronki at gmail dot com

--- Comment #1 from Dominik Gronkiewicz <gronki at gmail dot com> ---
Still persists in gfortran 14.

Minimal working example. Shows that copy is not performed correctly, but only
if the derived type is recursive with itself.

** Expected output: **

gfortran-14 test.f90 && ./a.out 
 a % child % val =            1
 b % child % val =            2
 now deallocating

** Actual output: **

gfortran-14 -g test.f90 && ./a.out 
 a % child % val =            2
 b % child % val =            2
 now deallocating

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fb4cf24157f in ???
#1  0x40123b in __testmod_MOD___deallocate_testmod_Mytype
        at /tmp/tmp.FUJSIzk4k0/test.f90:10
#2  0x4012a7 in __testmod_MOD___deallocate_testmod_Mytype
        at /tmp/tmp.FUJSIzk4k0/test.f90:10
#3  0x401bc9 in testprog
        at /tmp/tmp.FUJSIzk4k0/test.f90:31
#4  0x401c23 in main
        at /tmp/tmp.FUJSIzk4k0/test.f90:13

** Source starts here until the end **

module testmod
type :: mytype
   ! change anothertype->mytype to triger an error
   type(anothertype), allocatable :: child
   integer :: val
end type
type :: anothertype
   integer :: val
end type
end module

program testprog
   use testmod

   type(mytype), allocatable :: a, b

   allocate(a)
   allocate(a % child)

   a % child % val = 1
   allocate(b, source=a) 
   ! note: intrinsic assignment b = a
   ! causes the same problem as allocate/source
   b % child % val = 2

   print *, "a % child % val = ", a % child % val
   print *, "b % child % val = ", b % child % val
   print *, "now deallocating"

   deallocate(b)
   deallocate(a)

end program

Reply via email to