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

Runtime crash with elemental procedure, optional and non-optional arguments

Harald1
New Contributor II
472 Views

The following code compiles with ifort/ifx, but crashes at runtime as indicated:

program main
  implicit none
  integer :: arr(1) = 42
  call sub (arg2=arr)
contains
  subroutine sub (arg1, arg2)
    integer, intent(in), optional :: arg1(:)
    integer, intent(in)           :: arg2(:)
    print *, fun (arg2=arg2)    ! This works
    print *, fun (arg1, arg2)   ! This crashes at runtime
  end subroutine
  elemental function fun (arg1, arg2)
    integer, intent(in), optional :: arg1
    integer, intent(in)           :: arg2
    integer                       :: fun
    fun = arg2
  end function
end program

 I get:

% ifort ifort-elemental-optional.f90 -g -what && ./a.out 
 Intel(R) Fortran 2021.11.0-1242.01
          42
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
libpthread-2.31.s  000014D1CDCA7910  Unknown               Unknown  Unknown
a.out              00000000004039E9  Unknown               Unknown  Unknown
a.out              00000000004036E7  Unknown               Unknown  Unknown
a.out              000000000040365D  Unknown               Unknown  Unknown
libc-2.31.so       000014D1CDACF24D  __libc_start_main     Unknown  Unknown
a.out              000000000040358A  Unknown               Unknown  Unknown

It appears that passing the missing optional dummy argument arg1 to 'fun' fails.

 

3 Replies
David_Billinghurst
New Contributor III
445 Views

I believe your program conforms to the 2018 standard.

Section 15.5.2.12 Argument presence and restrictions on arguments not present ,  states

3 An optional dummy argument that is not present is subject to the following restrictions

[...]

4 Except as noted in the list above, it may be supplied as an actual argument corresponding to an optional dummy argument, which is then also considered not to be present.

 

The equivalent section 15.5.2.13 in Fortran 2023 appears identical.

Barbara_P_Intel
Employee
381 Views

@Harald1 and @David_Billinghurst, thank you for the report and the citation in the Fortran standards!

I filed a bug on your behalf, CMPLRLLVM-54890.

 

0 Kudos
Ron_Green
Moderator
254 Views

@Harald1 @David_Billinghurst we have a fix for this bug.  It's in the pipeline for the 2024 Update 2 release, 2024.2.  Roughly late June or July.  But don't hold me or Barbara to that. We only help get fixes and are not involved in validation and packaging. We can't control the release schedules.

0 Kudos
Reply