I get a segmentation fault, when running the following program compiled with iford 19.0 without any compiler options on linux.
! ifort (IFORT) 22.214.171.124 20181018 program ifort_bug_recursive_procedure_optional_value_dummy_argument implicit none ! works fine call sub(10, 0, 5) ! forrtl: severe (174): SIGSEGV, segmentation fault occurred call sub(10, 0) contains recursive subroutine sub(max, current, depth) ! iford bug if depth absent integer, intent(in) :: max integer, intent(in) :: current integer, value, optional :: depth ! integer, intent(in), optional :: depth ! fixes the bug logical :: step_in step_in = .true. if (present(depth)) then if (current > depth) return if (depth == 0) step_in = .false. end if if(step_in.and.(max >= current)) then print *, current ! if (present(depth)) then ! fixes the bug call sub(max, current+1, depth) ! else ! call sub(max, current+1) ! end if end if end subroutine sub end program ifort_bug_recursive_procedure_optional_value_dummy_argument
I tested versions 12.1 and 14.0.3, they compile with a warning
warning #7937: The OPTIONAL attribute should not be used for arguments with the VALUE attribute. [DEPTH]
recursive subroutine sub(max, current, depth) ! iford bug if depth absent
but the executable then only prints until 5, not until 10.
Since version 15.0.3, I do see the segmentation fault. nagfor and gfortran (at least since 5.4) work as expected, printing until 10, PGI 18.10 also generates a segmentation fault.
OPTIONAL and VALUE are allowed together if BIND is not used - there was some debate about this in the standards committee more than a decade ago (my first WG5 meeting!). However, it looks as if ifort isn't taking this into account when following the rules for how a not-present dummy argument is passed to a procedure where that argument is OPTIONAL. I agree that a bug report is in order.