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

    <tr>
        <th>Summary</th>
        <td>
            [flang] runtime error with "Recursive I/O attempted on unit"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Test code:
```console
$ cat test.f90
module md
  implicit none
contains
  function test1(a,b)
    integer,intent(in):: a, b
    integer test1
    test1 = test2(a,b)
    contains
      function test2(c,d)
 integer,intent(in):: c, d
        integer test2, i
        double precision x(c)
        test2 = c * d
        do i = 1, c
 x(i) = dble(i)/c
        end do
        print *, sum(x)
      end function test2
  end function test1
end module md

program main
  use md
  implicit none
  integer :: a = 100, b = 1
  print *, test1(a,b)
end program main
```

Result:
```console
$ flang-new -flang-experimental-exec test.f90
$ ./a.out

fatal Fortran runtime error(./test.f90:17): Recursive I/O attempted on unit 6
Aborted (core dumped)
```

Other compilers accept the code.
https://godbolt.org/z/zj3vre6Pr
https://godbolt.org/z/MdsxWzYGG
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE1v4zYQ_TXUZWCDHkm2ddDBTaBFD8UWiwJFjxQ5trmlSIEfibu_vqCkxLETIDEsiZyZN_M4fKQIQZ8sUcvq31j9WIgUz863_66E9-45FL1T_7V_UYggnSJWHhh_ZPzAtnz-S2eDM7RYsQIpIkQKcX1s-GwdnEqGYFDzFEAPo9FSR7DOLkjpbBTahpeQY7IyamenVBuGe8HwoWfYvAQAaBvpRJ7hQx7ZyHCvbY4oD6w8QAZA_y58SfhqnqbAysdphB9WuieXfzcEM0wyfFBX2CfscjSotwlvGWL261u_cqk3BKMnqUMufZnLNrdhE3xakQSGh_sqyoGevJtcQi7OnEozbCaP6g0tc4advMWTVaDcrW302sZcLKcMaWC4v9zxyrC7ni3ed55ld7L9Tjrze_Tu5MUAg9D2JUkKnwjs2t4XfcxN4HzSydKRJfRmPR8rMLN7T-T1WLzl-4NCMvELR-dohD2tLD3Dah7SZSSvB7JRmBVdSN6drAxaM-zE2qX4tuRRRGGgcz56YcEnG_VAQN47z3CfIa-JysNmN-sSfpBMPugngt8Zdt9BxEjDGEmBs5CsjrCd0x9657M56895ApWGka7i_7AL3-OZPEg3jNqQDyCkpDFCPNN0s6znqHOMY8itwo5hd3KqdyaunT8x7H7l52f55Gn7p_9a-B8qXP7-9c-3b4VqS9WUjSio3Wx325rXux0W57ZSTXWkfl-RKuuybna12hwbvq9VXcqy4YVukWPJcbPlnGON60pV_LhX5bZuuOx3Fas4DUKbtTFPQ65d6BAStVu-azaFET2ZMN2uiHlrJydDzJetbzNm1adTYBU3OsRwzRJ1NNO1PGmB1Y-3-wjPOp6BIX66awyxSN60d83S8Zz6tXQDwy4XXT6r0bufJCPDbqIaGHbTUv4PAAD__z38yuo">