The following Fortran code generates a segmentation fault when compiled with ifort version 19.0.3.199 without optimization (-O0
) on SLES 15:
program test_prg
call sub1()
contains
subroutine sub1(opt)
integer, allocatable, optional :: opt(:)
call sub2(opt)
end subroutine
subroutine sub2(opt)
integer, optional :: opt(:)
end subroutine
end program
I do not intend to allocate opt
within sub2
, so I did not specify allocatable
attribute there. If I make it allocatable in both subroutines or non-optional or if I pass an actual argument in the call to sub1
, then the code finishes without errors. The same code also runs fine when compiled with gfortran from gcc version 8.3.0 20190222.
Is it a compiler bug or am I doing something illegal here?
Fortran 2018 prohibits your use of opt
in sub1
. The restrictions on not present optional dummy arguments include (15.5.2.12):
An optional dummy argument that is not present is subject to the following restrictions.
...
(8) If it is allocatable, it shall not be allocated, deallocated, or supplied as an actual argument corresponding to an optional nonallocatable dummy argument.