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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Bug in IO runtime error?
        </td>
    </tr>

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

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

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

<pre>
    ```
program m_test

  real, target :: a(2,2) = reshape([1.,2.,3.,4.], [2,2])
  real,pointer,dimension(:):: t
  print *, test_func(a)
CONTAINS

  function test_func(i2) result(i1)
    implicit none
    real,dimension(:,:),target,intent(in):: i2
    real,pointer,dimension(:):: i1

    interface
       function ext_interface(ln,i2) result(i1)
       implicit none
       integer,intent(in) :: ln
       real,dimension(:,:),target,intent(in):: i2
       real,pointer,dimension(:):: i1
       end function ext_interface
    end interface
    print *, i2, size(i2)

    i1 => ext_interface(size(i2),i2)
  end
end

function ext_interface(ln,i2) result(i1)
  implicit none
  integer,intent(in) :: ln
  real,dimension(:),target,intent(in):: i2
  real,pointer,dimension(:):: i1
  i1 => i2
  print *, i2
end
```
```
$ gfortran test.f90 && ./a.out
test.f90:14:7:

   14 |        function ext_interface(ln,i2) result(i1)
      |       1
Warning: Interface mismatch in global procedure ‘ext_interface’ at (1): Rank mismatch in argument 'i2' (2/1) [-Wargument-mismatch]
   1.00000000       2.00000000       3.00000000       4.00000000               4
   1.00000000       2.00000000    
   1.00000000       2.00000000    
$ ifort test.f90 && ./a.out
   1.000000       2.000000       3.000000       4.000000               4
   1.000000       2.000000    
   1.000000       2.000000    
$ flang-new -flang-experimental-exec test.f90 && ./a.out

fatal Fortran runtime error(./test.f90:21): Could not acquire exclusive lock on unit 6, perhaps due to an attempt to perform recursive I/O
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVklzozgU_jVwUZkCATYcOD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