You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now to preface this, I am not sure if this is legal, illegal or UB in terms of the Fortran specification (so please do chime in any available Fortran guru's it would be greatly appreciated), however, it is something that we've encountered in the UMT benchmark that appears to be supported by gfortran and presumably other fortran compilers that currently support UMT.
In the below example, we effectively use a nullary optional argument as part of a string concatenation, in flang we segfault, in gfortran it will allow it and basically insert a blank character (the additional call to f90veify may be unnecessary to evoke the behavior, it's primarily the idiom that UMT uses).
module reproducers
contains
subroutine f90verify(message)
implicit none
character(*), intent(in) :: message
print *, "does nothing"
end subroutine
subroutine optional_test(h_ptr, label)
integer, intent(in), target, dimension(1) :: h_ptr
character(len=*), intent(in), optional :: label
call f90verify("Failed to allocate " // label // " on device.")
end subroutine
end module reproducers
program main
use reproducers
integer :: test(10)
call optional_test(test)
end program
So I suppose, if this is UB, but other compilers do something more "reasonable" than segfault, then the question would be if we wish to follow suit and fix it to conform with the gfortran and friends.
If it is legal, then it's likely something we wish to fix.
If it is illegal, then it's likely not flang's problem, and it's up to UMT to alter their source code to be legal.
But if it is something that requires fixing in flang, then it's likely there is someone more suitable to fixing this issue than I am as I am not particularly familiar with how optional or characters are handled in Flang at the moment.
The text was updated successfully, but these errors were encountered:
This usage is not conforming -- there's no carve-out for character concatenation (//) as an exception to references to absent optional dummy arguments in F'2023 15.5.2.13. But this usage works with literally every other Fortran compiler to which I have access (7), so it's portable, and this compiler must support it, at least with assumed-length character arguments as in this test case.
My suspicion is that the compiler should be passing 0 for the length of the absent assumed-length character argument but does not. Printing LEN(label) before the crash reveals an uninitialized-looking big negative integer.
Now to preface this, I am not sure if this is legal, illegal or UB in terms of the Fortran specification (so please do chime in any available Fortran guru's it would be greatly appreciated), however, it is something that we've encountered in the UMT benchmark that appears to be supported by gfortran and presumably other fortran compilers that currently support UMT.
In the below example, we effectively use a nullary optional argument as part of a string concatenation, in flang we segfault, in gfortran it will allow it and basically insert a blank character (the additional call to f90veify may be unnecessary to evoke the behavior, it's primarily the idiom that UMT uses).
So I suppose, if this is UB, but other compilers do something more "reasonable" than segfault, then the question would be if we wish to follow suit and fix it to conform with the gfortran and friends.
If it is legal, then it's likely something we wish to fix.
If it is illegal, then it's likely not flang's problem, and it's up to UMT to alter their source code to be legal.
But if it is something that requires fixing in flang, then it's likely there is someone more suitable to fixing this issue than I am as I am not particularly familiar with how optional or characters are handled in Flang at the moment.
The text was updated successfully, but these errors were encountered: