The following code produces a memory error when compiled with recent versions of gfortran (10.3 or later):
module distributed_array
  implicit none
  type :: darray_segment
    integer::rank
    integer::offset
    integer::length
    real(kind=8), allocatable::data(:)
  contains
  end type darray_segment
  type :: darray
    type(darray_segment), allocatable::segments(:)
  end type darray
contains
  function new_darray(segments)
    class(darray_segment), intent(in)::segments(:)
    type(darray)::new_darray
    new_darray%segments = segments
  end function new_darray
end module distributed_array
program test_darray
  use distributed_array, ONLY: darray, darray_segment, new_darray
  implicit none
  integer, parameter::np_src = 4
  integer, parameter::np_dest = 3
  type(darray)::src_darray
  type(darray)::dest_darray
  type(darray_segment)::src_segments(np_src)
  type(darray_segment)::dest_segments(np_dest)
  src_darray = new_darray(src_segments)
  dest_darray = new_darray(dest_segments)
end program test_darray
The output produced is as follows:
darray_test: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0  0x7f727c59fbf0 in ???
#1  0x7f727c59ee45 in ???
#2  0x7f727c20d83f in ???
    at /build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3  0x7f727c20d7bb in __GI_raise
    at ../sysdeps/unix/sysv/linux/raise.c:51
#4  0x7f727c1f8534 in __GI_abort
    at /build/glibc-vjB4T1/glibc-2.28/stdlib/abort.c:79
#5  0x7f727c255a67 in __malloc_assert
    at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:298
#6  0x7f727c257e6e in sysmalloc
    at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:2382
#7  0x7f727c2592c8 in _int_malloc
    at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:4133
#8  0x7f727c25a3e2 in __GI___libc_malloc
    at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:3049
#9  0x401f10 in __distributed_array_MOD_new_darray
    at /test/src/test/darray_tests.F90:23
#10  0x402933 in test_darray
    at /test/src/test/darray_tests.F90:44
#11  0x402aaf in main
    at /test/src/test/darray_tests.F90:31
The code runs without error when compiled with gfortran 4.9.4 and 10.2, but the above error occurs with versions 10.3 and 11.
The problem appears to be related to the assignment operation new_darray%segments = segments. If I declare segments as type(darray_segment) instead of class(darray_segment), then the program no longer crashes. So apparently the problem is triggered by assignment from a polymorphic variable. Is such assignment supposed to be allowed per the Fortran standard?