https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104900
Bug ID: 104900 Summary: segfault with parameterized derived type with kind parameter and allocatable component 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: --- Created attachment 52617 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52617&action=edit sample source code The attached file contains a is a valid Fortran standard program with parameterized derived types with kind type parameter (no len parameter) and an allocatable component. However, gfortran yields a runtime segfault with this code, ``` use, intrinsic :: iso_fortran_env!, only: real64, int64 integer, parameter :: RK1 = real_kinds(1) integer, parameter :: RK2 = real_kinds(2) type :: Container_type(RK) integer, kind :: RK = RK1 real(RK), allocatable :: value(:) end type type(Container_type(RK1)), allocatable :: List(:) interface wrap procedure :: wrap_RK1, wrap_RK2 end interface List = wrap([1.,2.,3.,4.,5.,6.]) print *, List(1)%value print *, List(2)%value contains function wrap_RK1(array) result(List) real(RK1), intent(in) :: array(:) type(Container_type(RK1)), allocatable :: List(:) allocate(List(2)) List(1)%value = array(1:size(array)/2) List(2)%value = array(size(array)/2 + 1 : size(array)) end function function wrap_RK2(array) result(List) real(RK2), intent(in) :: array(:) type(Container_type(RK2)), allocatable :: List(:) allocate(List(2)) List(1)%value = array(1:size(array)/2) List(2)%value = array(size(array)/2 + 1 : size(array)) end function end ``` Here is the error message, ``` Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7f1e57dcc8d2 in ??? #1 0x7f1e57dcba65 in ??? #2 0x7f1e57a430bf in ??? #3 0x401927 in wrap_rk1 at /app/example.f90:27 #4 0x4012f4 in MAIN__ at /app/example.f90:17 #5 0x401bfc in main at /app/example.f90:19 ``` There segfault happen where the automatic allocation of the `value` component occurs in the procedures. Here is an online test: https://godbolt.org/z/8n5fs44sa