Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28488 Discussions

iford 19.0 bug recursive procedure with optional, value dummy argument

Elias_L_
Beginner
578 Views

Hi,

I get a segmentation fault, when running the following program compiled with iford 19.0 without any compiler options on linux.

! ifort (IFORT) 19.0.1.144 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

 

0 Kudos
3 Replies
FortranFan
Honored Contributor II
578 Views

This looks like a bug in Intel Fortran compiler, you can submit a support request: https://supporttickets.intel.com/?lang=en-US

0 Kudos
Juergen_R_R
Valued Contributor I
578 Views

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.

0 Kudos
Steve_Lionel
Honored Contributor III
578 Views

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.

0 Kudos
Reply