https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61831
--- Comment #29 from Jürgen Reuter <juergen.reuter at desy dot de> --- A trivial workaround for the problem is to replace (In reply to Dominique d'Humieres from comment #28) > > Created attachment 33158 [details] > > Reduced test case, 140 lines > > Further reduced to > > program main > implicit none > > type :: string_t > character(LEN=1), dimension(:), allocatable :: chars > end type string_t > > type(string_t) :: prt_in > integer :: i > prt_in = string_t(["W"]) > do i = 1, 16 > print *, i > call process_configuration (new_prt_spec ([prt_in])) > end do > > contains > > elemental function new_prt_spec (name) result (prt_spec) > type(string_t), intent(in) :: name > type(string_t) :: prt_spec > end function new_prt_spec > > subroutine process_configuration (prt_in) > type(string_t), dimension(:), intent(in) :: prt_in > end subroutine process_configuration > > end program main > > and it does not require iso_varying_string!-) > > With 4.9.0 it counts up to 16, while with 4.9.1 and 4.10 with/without the > patch in comment 23 it gives > > 1 > 2 > a.out(71763,0x7fff7bc1d310) malloc: *** error for object 0x7fe788e00000: > pointer being freed was not allocated > *** set a breakpoint in malloc_error_break to debug > ... A trivial workaround is to replace call process_configuration (new_prt_spec ([prt_in])) by call process_configuration ([new_prt_spec (prt_in)]) However, nevertheless you would want to understand why the elemental function causes a malloc crash for dim 1 arrays and works for scalars and dim > 1 arrays as input.
