- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page