https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100440
--- Comment #6 from anlauf at gcc dot gnu.org ---
There seems to be something fishy with default initialization of function
results of derived types. Looking at the attached code, I guessed the
following potential reproducer:
program p
implicit none
type multi
real, allocatable :: mp(:)
end type
type fm
type(multi) :: mfm
end type
type(fm), allocatable :: a(:,:)
integer :: n = 1
allocate (a(n,n))
a = mm (a, a)
a = mm (a, a) ! crashes here with -fsanitize=address
contains
function mm (ma, mb)
type(fm) :: ma(:,:), mb(:,:)
type(fm), dimension(size(ma,dim=1),size(mb,dim=2)) :: mm
integer :: i, j
do i = 1, size(ma,dim=1)
do j = 1, size(mb,dim=2)
print *, i, j, allocated (mm(i,j)% mfm% mp)
end do
end do
end function mm
end program p
Compiling and running the program prints:
1 1 F
1 1 T
The second output line should really be identical to the first one, which is
confirmed by other compilers.
Under Linux, setting MALLOC_PERTURB_=1 I get:
1 1 T
1 1 T
Adding -fsanitize=address to the command line, I get a traceback pointing
to the line commented above:
1 1 T
1 1 T
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x14c71f85649f in ???
#1 0x14c720845c36 in
_ZN11__sanitizer30atomic_compare_exchange_strongINS_14atomic_uint8_tEEEbPVT_PNS2_4TypeES5_NS_12memory_orderE
at
../../../../gcc-trunk/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:80
#2 0x14c720845c36 in
_ZN6__asan9Allocator38AtomicallySetQuarantineFlagIfAllocatedEPNS_9AsanChunkEPvPN11__sanitizer18BufferedStackTraceE
at ../../../../gcc-trunk/libsanitizer/asan/asan_allocator.cpp:621
#3 0x14c720845c36 in
_ZN6__asan9Allocator10DeallocateEPvmmPN11__sanitizer18BufferedStackTraceENS_9AllocTypeE
at ../../../../gcc-trunk/libsanitizer/asan/asan_allocator.cpp:697
#4 0x14c720845c36 in
_ZN6__asan9asan_freeEPvPN11__sanitizer18BufferedStackTraceENS_9AllocTypeE
at ../../../../gcc-trunk/libsanitizer/asan/asan_allocator.cpp:971
#5 0x14c7208cac07 in __interceptor_free
at ../../../../gcc-trunk/libsanitizer/asan/asan_malloc_linux.cpp:128
#6 0x401f10 in p
at /home/anlauf/Downloads/pr100440-red.f90:13
#7 0x402180 in main
at /home/anlauf/Downloads/pr100440-red.f90:13