https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100440
--- Comment #12 from anlauf at gcc dot gnu.org --- A small variation of the testcase in comment#9 suggests that there are actually two underlying issues: lack of initialization and a missing temporary. program p implicit none type fm real, allocatable :: mp(:) integer :: dummy = 42 end type type(fm), allocatable :: a(:), b(:) integer :: n = 1 allocate (a(n)) print *, "main:", n, allocated (a(n)% mp), a(n)% dummy b = mm (a) a = mm (b) a = mm (a) a = mm (a) ! crashes here with -fsanitize=address contains function mm (ma) type(fm), intent(in) :: ma(:) type(fm) :: mm(size(ma)) integer :: i ! type(fm) :: z(size(ma)) ! mm = z ! Explicit initialization of function result do i = 1, size(ma) print *, "in mm:", i, allocated (mm(i)% mp), mm(i)% dummy end do end function mm end program p This gives: main: 1 F 42 in mm: 1 F 0 in mm: 1 F 42 in mm: 1 F 0 in mm: 1 T 0 while with -fsanitize=address,undefined : main: 1 F 42 in mm: 1 F -1094795586 in mm: 1 F 42 in mm: 1 T -1094795586 in mm: 1 T -1094795586 Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x14987da6f49f in ??? [...] #6 0x409669 in p at /home/anlauf/gcc-bugs/pr100440-red3.f90:14 #7 0x4097d9 in main at /home/anlauf/gcc-bugs/pr100440-red3.f90:14