<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112593>112593</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Optional character argument used in string concatenation causes segfault
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
agozillon
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0Vk1v4zgM_TXKhZggVpo2OeTQThFgDrt72J3zgJZpm1tZ8ugjmeyvX1B2PjpogcKpaYl-75F6NMbInSPaq82L2rwuMKfehz12_j-21rtF7Zvz_k9_guRhDNSiIUg9R6W_wjfAAZxPEHMg4LY8AI5gqUMrK9iWf8EH-P4C7CB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