Hello. It’s my first time messing with parameterized derived types and I’m not sure what’s happening here. Is the following program legal?
program test
implicit none
type :: mytype_t ( l )
integer, len :: l = 40
real :: arr(0:l-1)
end type
type(mytype_t) :: a
a%arr(0) = 1.0
end program
It compiles without warnings but crashes when executing. Here’s what I get
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)
$ ./a.out
double free or corruption (out)
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0 0x7ff39de218c2 in ???
#1 0x7ff39de20a55 in ???
#2 0x7ff39dc5b04f in ???
at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
#3 0x7ff39dca9ebc in __pthread_kill_implementation
at ./nptl/pthread_kill.c:44
#4 0x7ff39dc5afb1 in __GI_raise
at ../sysdeps/posix/raise.c:26
#5 0x7ff39dc45471 in __GI_abort
at ./stdlib/abort.c:79
#6 0x7ff39dc9e42f in __libc_message
at ../sysdeps/posix/libc_fatal.c:155
#7 0x7ff39dcb3839 in malloc_printerr
at ./malloc/malloc.c:5660
#8 0x7ff39dcb589f in _int_free
at ./malloc/malloc.c:4584
#9 0x7ff39dcb7f1e in __GI___libc_free
at ./malloc/malloc.c:3385
#10 0x5613eb322224 in ???
#11 0x5613eb32226a in ???
#12 0x7ff39dc46249 in __libc_start_call_main
at ../sysdeps/nptl/libc_start_call_main.h:58
#13 0x7ff39dc46304 in __libc_start_main_impl
at ../csu/libc-start.c:360
#14 0x5613eb3220a0 in ???
#15 0xffffffffffffffff in ???
Aborted (core dumped)
This won’t happen if I don’t specify a lower bound for arr
.
Any help appreciated.