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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Runtime failure at the READ statement of list-directed I/O with an array input item.
        </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 dataType
        complex, allocatable :: cx
    end type

    type base
        character(20), pointer :: name => null()
        real, allocatable :: data
 class(dataType), allocatable :: d2
    end type

    interface read(formatted)
        procedure readBaseFmtd
        procedure readDataTypeFmtd
    end interface


    contains

    integer function currentPos (s)
        character(*), intent(in) :: s

        currentPos = len (trim(s)) + 1
    end function

    subroutine readDataTypeFmtd (dtv, unit, iotype, v_list, iostat, iomsg)
        class(dataType), intent(inout) :: dtv
        integer, intent(in) :: unit
        character(*), intent(in) :: iotype
        integer, intent(in) :: v_list(:)
        integer, intent(out) :: iostat
        character(*), intent(inout) :: iomsg

 if (.not. allocated(dtv%cx)) allocate (dtv%cx)

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

    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

        if (.not. associated(dtv%name)) allocate (dtv%name)

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

 if (iostat /= 0) error stop 1

        if (.not. allocated(dtv%data)) allocate (dtv%data)

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

        if (iostat /= 0) then
 print*, iomsg
          error stop 2
        end if

        if (.not. allocated(dtv%d2)) allocate(dtv%d2)

        read (unit, *, iostat=iostat, decimal='COMMA', iomsg=iomsg) dtv%d2

        if (iostat /= 0) error stop 3

    end subroutine
end module

program modeInquire002
use m
 class(base), allocatable :: b1(:)
    integer :: j = 3 !! If j is less than 3 or b1 is a scalar, the code works fine.


    open (1, file='modeInquire002.data')

    write (1, &
 fmt='("''", a, "'' ",dp,e15.8, " (", dc, e15.8," ; ",e15.8," ) ")', &
            sign='plus') &
            ('xlftest '//achar(iachar('0') + i-1), i*1.2, &
                cmplx(sin(i*1.1), cos(i*1.1), 4), i=1,j)

    rewind 1

    allocate (b1(j))

    read (1,*) b1

end
```

Flang failed at the runtime with:
```
> a.out
 Bad real input data at column 64 of record 1

Fortran ERROR STOP: code 2

IEEE arithmetic exceptions signaled: INEXACT
```

If `b1` is a scalar or has less than 3 elements, it works fine.

Both gfortran and XLF compile and executes the code successfully.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkV0lv47gS_jX0pRBDorzIBx8cOwYCvH5p5PWhbw80VbKZoUgNSWX594OipFjeBtM9Pacxgpgma6-vikXhvdobxCWb3rPpZiSacLBuuRFGoV6vD2hGO1t8LNfWeFWgg3BAKK3W9k2ZPUhbIMtWLFmxWdL9JavKFo1GqFiyAgAIHzVCIYL49lFjt0cfaata4zvjaxBaWymC2GkEkpetQL53pGiKKIKUDATuhD8RdhBOyICO8ZwnjC9IbG2VCeh6kUZUJH7DsgcwjdaM50R4FOJQ6BvmkP1EKbXwnvH8059W0zUOftOBaFUpJJLGgvG8tK4SIWBxak_trMSicS3dvfC4rUJxk2DT2TQgIt2f2loDuhNpTRDK-FOr9uigbIwMyhqQjXNowlfrgfHcn9o2DDjjqy4OJMMExnNlGF_0oRgoiawDudkGNBqSH5yqejXEyu8hHXjRW3UU5Zuds01Q5tJ7kleEV7KoMSpEy2zMAV_D6_-18t2eD6JbVX5_5uD1TA88tE0YOEn6jtxdMG_HJNr1c-HsXPkBZb3LOf0-8fIa66lfXZB-wNRzfgptmzVVUmbGxoZxXzKE-TZXU_ne5b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