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

    <tr>
        <th>Summary</th>
        <td>
            Flang does not match any OpenMPI subroutine when called with an element of an assumed-shape array
        </td>
    </tr>

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

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

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

<pre>
    Below you see a simple MPI Fortran program which doesn't compile with flang-new using `use
mpi` or `use mpi_f08` but works fine with `include 'mpif.h'`. I'm testing with OpenMPI (version 4.1.6).

This only seems to be triggered when you pass an array into a subroutine as an assumed-shape array and use a single element of it as the argument to `mpi_recv`. Putting the same call to `mpi_recv` into the main program body works fine.

This is the error I'm getting:
```
./mpitest.f90:34:5: error: No specific subroutine of generic 'mpi_recv' matches the actual arguments
      call mpi_recv(x(5), 1, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
 

The same program works fine and correctly using gfortran.

This is the test program:
```f90
program test
  ! Neither of these options work with flang-new.
  use mpi
  ! use mpi_f08

  ! This compiles with flang-new
  ! include 'mpif.h'
 
  integer :: rank, ierr
  integer, parameter :: n=10
  integer :: b(n)

  call mpi_init(ierr)

  call mpi_comm_rank(MPI_COMM_WORLD, rank, ierr)

  b = rank

  if (rank == 0) then
     call mpi_ssend(b(1), 1, MPI_INTEGER, 1, 0, MPI_COMM_WORLD, ierr)
  else
 call recv(b)
  end if

  print*, rank, ': ', b

  call mpi_finalize(ierr)

contains
  subroutine recv(x)
    integer :: x(:)
    call mpi_recv(x(5), 1, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierr)
  end subroutine recv
end program test
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVlFvqzgT_TXOy6gITELgIQ-5t81Vpa_tVW8_7WNlYABvwUa2aTb761djSEKa9j7uy0YRCePDeObMzMHCWlkrxA1bfWOr24UYXKPNxg1v1i5yXR4237DVezjoASwiCLCy61uEh5_3sNPGGaGgN7o2ooN9I4sGSo1WMb52UOiuly3CXroGqlao-kbhHgYrVQ0sCQeLLLxl4bbrJUtC0GayQtfL1ypMyZgPDvbavFmopJp8sSSUqmiHEoHxddfLKmgYX7MkDOCeLODQOtrFw596VBQv4-k7Giu1gmUQBQnjWTAGMF5fGmlBq_ZAqXYWnIYcwRlZ12iwhH2DyjPRC2tBKBDGiANI5TQRM-RGD46CFOOqtUOH5Y1tRI8TVqgSKEHiUdUtArbYoXKgK5COHnQNYevBW52mXIkNg8W7z-_n4HxmhLOiQyhE214Dx6gI1Al5LhGVdEbndfpyjACN0Wbiska_I4snHEvC6etvA8Z3XS-J8aDKQhZv4yWLtysWb0c39OdRg-2xkJUs5kTpCmpUaGQxFXIMn6-hE65ocKKjcINoT6zYcV_wH5_9-cH0L8bTFeMZ498hosvDz_vX-8eXux93z3Qbni608P3p4eH1j6fn_90eLb9eti____V6_-Px6fmOjBKNIX_jnmx191_8flZ3uOydqRtPWnAeWer5QhuDhWsP0_TX1agdXzYgtdPR2XXnUZ95y3E7gh_bgvEIHlG6Bg01mGvQIujeSa2sj-uDIAXHByflmfuZi9Es0nHRxzuJnP3gdI77VKvmHAJNK9ZogFKNt2CEejs13yWEzL0wokN3xisW30bhF85yxlN1auEj6DQ4UknHeHrR51egQnfd6xhVej04F-F-9JEDi29HyIVdViTIZCcAYULGMyqXmg34KQJrUZWMp5RN9JsBj34z4JezDNgeX0DjNpOE5HOIKkFWl4H3RirH-HaeOVU03vof_h3yL1ispBKt_Bs_p7vQygmpTvI208mzuGVnbj6UmZSP_s4h_7I6ero-hu2XaOF6Vk_zvCg3cZnFmVjgJlpHIU-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