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

    <tr>
        <th>Summary</th>
        <td>
            [flang][runtime][IO] OPEN statement core dumps at runtime with not-existent file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mjklemm
      </td>
    </tr>
</table>

<pre>
    When compiling below reproducer and running it with the opened file not being there, the executable core dumps:

```
$  flang-new -o readtest ./readtest.f90       
$  ./readtest 

fatal Fortran runtime error(/path/path/path/readtest.f90:9): End of file during input
[1]    1099765 IOT instruction (core dumped) ./readtest
```

The expected output would be:

```
 ERROR
```

Reproducer:

```Fortran
program readtest
    implicit none
    character(len=10) :: dir_app
    real(8) :: rdum, rispin
 integer :: idum

    open(unit=12, file='data1.dat', access='direct', form='unformatted',status='unknown', recl=128)

 read(12,rec=1,err=17421) rdum,rispin ; idum=nint(rdum)

    write (*,*) rdum, rispin
    return

    17421 write(*,*) "ERROR"
end program
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVE2PozgQ_TXmUkoEJiRw4EB3OtJctletkfa4MnYRPGNsZJcns_9-ZSDdmemJUPior_delUuEoK8WsWXVE6vOmYg0Ot9O374bnKasd-q_9p8RLUg3zdpoe4UejbuBx9k7FSV6EFaBj9Ymoya4aRqBRgQ3o0UFgzYI1hH0mDxoRI-MPy8u-BNlJNEbBOk8gorTHFjZsXy5jvl25R3jB4DBCHvdWbzBzoFHoQgDwZ7xy_1lPzQ5rL970KMZ1sSDIGHg4jx5YRN20hMCeu884zXjl1nQ-On2WIOVXcN4w8oOXqwCN6w0VfSLCnaOlEpVTwWrzglNkTfN6VjBl9evoG0gHyVpZ4Hx-p05KsabX_D-LkLefV1Um1ESKnCR5khwc9Eo6PGPwsHL29vr2-dEb-8N_By2KcPybvbu6sUED4ASGz3NRktNYJ3F7ZschReSMElo0LLyXOSJT0pfdqC0_1fM8-bsURjG6_rBwas4pbnwOsw61QZtCa_o7w46OSxAU4Y0XYzX0WpKpXgKTT1g5ZnxkxIkir0SxPgpWYSUGMJm0x7l3TA4P62fo03Pgii1IdkCCYrhbvxu3c1uQR6lWYom_BukpBDj9QLEo0xmxp_R-_R0OvAiUd04rhSBlU8rqfJstSXG69XefLC8eU0Iy1B2jD8v_80fpFokpejtR-hSdE3wezzjfJ0KzlneoVWw9flxCDLVlqopG5FhW5zKY3ksiiLPxnbAU5U3J1Ee60OPhRSF7A9NJfAgKtULkemW57zKi7wu6rI4NHsu62NxHE6ohl5UvWSHHCehzd6YH9Pe-WumQ4jYFpwXVZ4Z0aMJy0rifDnzCWh1znybAnZ9vAZ2yI0OFD5SkCaz7LE1ojqz6mk72uvLl9d0Fl__fvkLUmtxQksPawcEva-CZYdZRzv8qQMlvzRaWfSmHYnWFcUvjF-umsbY76WbGL8kKNttN3v3bZmyy0ItMH7Z2P1o-f8BAAD__97fpjE">