I totally agree. The intrinsic support of arrays is a nice feature of Fortran, and it should not be a feature that can easily lead to crashes.
For example, the following code will crash with a segmentation fault on Linux or Mac when i = 10 if compiled with ifort without any options. In today’s applications, a matrix of size 1024-by-1024 is really not that big. I would be surprised if a new user of Fortran is not surprised by this behavior.
Code:
module s_mod
implicit none
private
public :: sf_auto
contains
function sf_auto(n) result(s)
integer, intent(in) :: n
real(kind(0.0D0)) :: s
real(kind(0.0D0)) :: x_auto(n, n)
x_auto = 1.0D0
s = sum(x_auto)
end function sf_auto
end module s_mod
program test_mem
use :: s_mod, only:sf_auto
implicit none
integer :: i
do i = 1, 30
write (*, *) 2**i, sf_auto(2**i)
end do
end program test_mem
Result:
$ uname -a && ifort --version && ifort test.f90 && ./a.out
Linux zP 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
ifort (IFORT) 2021.8.0 20221119
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
2 4.00000000000000
4 16.0000000000000
8 64.0000000000000
16 256.000000000000
32 1024.00000000000
64 4096.00000000000
128 16384.0000000000
256 65536.0000000000
512 262144.000000000
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
libc.so.6 00007F8B6540A520 Unknown Unknown Unknown
a.out 0000000000404275 Unknown Unknown Unknown
a.out 000000000040415D Unknown Unknown Unknown
libc.so.6 00007F8B653F1D90 Unknown Unknown Unknown
libc.so.6 00007F8B653F1E40 __libc_start_main Unknown Unknown
a.out 0000000000404075 Unknown Unknown Unknown