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?