<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154791>154791</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Reading NULL input field failure
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:runtime
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DanielCChen
</td>
</tr>
</table>
<pre>
Consider the following code:
```
module m
type A
integer :: i = -1
end type
interface read (formatted)
subroutine formattedRead (dtv, unit, iotype, vlist, iostat, iomsg)
import A
class (A), intent(inout) :: dtv ! tcx: (4)
integer, intent(in) :: unit
character (*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
end subroutine
end interface
end module
subroutine formattedRead (dtv, unit, iotype, vlist, iostat, iomsg)
use m, only:A
class (A), intent(inout) :: dtv ! tcx: (4)
integer, intent(in) :: unit
character (*), intent(in) :: iotype
integer, intent(in) :: vlist(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
dtv%i = -1
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%i
end subroutine
program fdtio515a1kl
use m
type(a) a1(3)
write (1, *) '1, ,3, 4'
write (1, *) ', 20,30,40'
rewind (1)
read (1, *) a1
if (any (a1%i /= (/1, -1, 3/))) ERROR STOP 1
read (1, *) a1
if (any (a1%i /= (/-1, 20, 30/))) ERROR STOP 2
close (1, status='delete')
end
```
The intention of the testing is the 1st READ statement reads `1, ,3, 4`, because the second field is NULL, `a1%i(2)` after the 1st READ is assigned `-1`.
On the 2nd READ statement, the first field in `, 20, 30, 40` is NULL, so `a1%i(1)` after the 2nd READ should be also `-1`.
It seems ifort, gfortran and XLF all produce the expected output for the 1st READ. But Flang outputs `1, 3, 4`.
The compilers behaves differently on the 2nd READ though.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vt1u4zYTfRr6ZhCDomRb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