<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/154979>154979</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] DTIO failure with list-directed READ
        </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 base
        real, allocatable :: data(:)
        complex(8), allocatable :: cx(:)

        contains

 procedure :: readBaseFmtd
        generic :: read(formatted) => readBaseFmtd
    end type

    contains

    !! read in the array size before allocating dtv's components
    subroutine readBaseFmtd (dtv, unit, iotype, v_list, iostat, iomsg)
        class(base), intent(inout) :: dtv
 integer, intent(in) :: unit
        character(*), intent(in) :: iotype
        integer, intent(in) :: v_list(:)
        integer, intent(out) :: iostat
        character(*), intent(inout) :: iomsg

 integer isize

        read (unit, *, iostat = iostat, iomsg=iomsg) isize

        if (allocated(dtv%data)) deallocate (dtv%data)

 allocate (dtv%data(isize))

        read (unit, *, iostat=iostat, iomsg=iomsg) dtv%data

        read (unit, *, iostat = iostat, iomsg=iomsg) isize

        if (allocated(dtv%cx)) deallocate (dtv%cx)

 allocate (dtv%cx(isize))

        read (unit, *, iostat=iostat, iomsg=iomsg) dtv%cx
    end subroutine
end module

program dcmlChildRead003a1
use m
    integer currentPos, ss

    type(base) :: b1(2)


    open (1, file='dcmlChildRead003.data', access='stream', form='formatted', &
            decimal='Comma')

    write (1, '(i4, 10(g15.7))', pos=1, decimal='Point') 10, (i*1.0, i=1, 10)

    inquire (1, pos=currentPos)

    write(1, *, pos=currentPos, decimal='point') 12, (cmplx(i*1.0, i*2.0, 8), i=-12, -1)

    write (1, *) 20, (i*1.22, i=1,20)
    write (1, *, sign='plus') 22, (cmplx(i*1.1, i*2.2,8), i=-10,11)

    allocate (b1(1)%cx(3), b1(2)%data(1000))
    read (1, '(dp, dt, dc, dt)', pos=1) b1

print*, size(b1(1)%data)
print*, size(b1(1)%cx)

end
```

The test case prepared an input file. Then resized the components of the input item based on the `isize` that is read from the input file.
Flang seems failed to update the `isize` at the 2nd READ inside of the DTIO procedure.

The expected output is
```
> a.out
 10
 12
```

Flang has
```
> a.out
 10
 10
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVk2P4ygQ_TXkgjrCOB_OIQdPMpH2tKPR3FfYVGJWGLyAe7rn168K7LbjTu_sHFYbtTo28IpXrz5Swnt1MwBHsv1EtueV6ENj3fEsjAJ9OjVgVpWVr8eTNV5JcDQ0QK9Wa_tdmRutrQSSl4SVZMeGP1a2VvYaaEtYSSml4bUDWgkPwzt-HAhN-IkKrW0tgqg0UDSUl1SKIAgv8I0fZpDatp2GF8KLAjceg-uXOfQObYJQxg-rnbM1yN69AR0I-Ul4uLRBzmA3MOBUPT9FeHG1rhUhgCT8QEl-JvnnRwbAyOj8xGTBglJKeEZ4FtFUmSivcE68Uq9-AK3gah2MjqLiMjwTvvdRDWvABD8Y8n3lbB-UgTsqlPAiYk60Nyrgt7KRFD_R5z-08sOaD2J4av1tobwW3hNexBgm6ZUJYALhhTK2D0mGFL3wjEjcv4FbHJ2di2RmVzTCiTogoiC8fH_LDDrwn8A_vWz0831SPYLeOzQo8wtUl3jUM8V7uI0qDO59fsYEILwYgxQtj3HBHHsXovw8huqRPXVFa0PiYKKmLNim6jogSsK4Td9tJ1sf7RfpwmjmF9yIlD90YnbB_6IMto4PdUmbH6kSu85_p0n9MmsoU50TVuJC6rbpys7ZmxMtlXWrT43S8isIyVguMsLK3k89eczEuncOTPhiPd7vZ40p9Yix5sdsrjLCC_7m4nDWdmDQwwyNXJUG7Il8v2SxTtmzj727rsH7dM4HB6IdNrC3puVZl90n3XYzVfEjoVat0On4ybZtsj7T_7tTKVBZsrDHQG3wOWOEF7dsu94PMUuXdBZJxdN31r9YheWNhyMUj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