<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93707>93707</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Unexpected generic interface symbol reference causes error in mangling
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rofirrim
</td>
</tr>
</table>
<pre>
Consider the following module, simplified from a real module of OpenMPI
```fortran
! mini_mpi.f90
module mini_mpi
interface
subroutine mpi_allreduce(sendbuf,recvbuf,count,datatype,op,comm,ierror)
real(4),intent(in)::sendbuf(10)
real(4)::recvbuf(10)
integer(4),intent(in)::count
integer(4),intent(in)::datatype
integer(4),intent(in)::op
integer(4),intent(in)::comm
integer(4),intent(out)::ierror
end subroutine mpi_allreduce
end interface
! Generic interface
interface mpi_allreduce
procedure :: mpi_allreduce
end interface
contains
end module mini_mpi
```
And the following three modules, each one in a different file (stated in the first comment)
```fortran
! comm.f90
module comm
use mini_mpi
contains
subroutine my_sub_in_comm
real(4)::sendbuf(10)
real(4)::recvbuf(10)
integer(4)::count
integer(4)::datatype
integer(4)::op
integer(4)::comm
integer(4)::ierror
call mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm, ierror)
end subroutine my_sub_in_comm
end module comm
```
```fortran
! math.f90
module math
use comm
contains
subroutine my_sub_in_math
real(4)::sendbuf(10)
real(4)::recvbuf(10)
integer(4)::count
integer(4)::datatype
integer(4)::op
integer(4)::comm
integer(4)::ierror
call mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm, ierror)
end subroutine my_sub_in_math
end module math
```
```fortran
! mesh.f90
module mesh
use comm
use math
contains
subroutine my_sub_in_mesh
real(4)::sendbuf(10)
real(4)::recvbuf(10)
integer(4)::count
integer(4)::datatype
integer(4)::op
integer(4)::comm
integer(4)::ierror
call mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm, ierror)
end subroutine my_sub_in_mesh
end module mesh
```
If we compile them in the proper order
```
flang-new -c mini_mpi.f90
flang-new -c comm.f90
flang-new -c math.f90
flang-new -c mesh.f90
```
`mesh.f90` fails to compile with the following error
```
LLVM ERROR: <path>/llvm-src/flang/lib/Lower/Mangler.cpp:174: not yet implemented: symbol mangling
```
We try to mangle a `GenericDetails`.
It seems the problem stems in the exported symbols my `math` (and `mesh`) in which we see repeated references to `mpi_allreduce` (this suggests we might be exporting both the generic interface name and the external name) from these modules.
```
$ grep -rw mpi_allreduce {mesh,math}.mod
mesh.mod:use comm,only:mpi_allreduce
mesh.mod:use math,only:comm$mini_mpi$mpi_allreduce
math.mod:use comm,only:mpi_allreduce
math.mod:use mini_mpi,only:comm$mini_mpi$mpi_allreduce=>mpi_allreduce
```
but somehow is not a problem for `comm` (which is hopefully exporting only the generic name?)
```
$ grep mpi_allreduce comm.mod
use mini_mpi,only:mpi_allreduce
```
The problem seems related to the generic interface in `mini_mpi.f90` because commenting it solves the problem. But modifying the OpenMPI module is a bit of an inconvenient workaround.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEuP2zYQ_jX0ZbCGTPl58MGx4yJAghRBH8cFRY0kthQpkNQ6_vcFKVkry_LG215yaBAE0ZCcB79vPo3MrBW5QtySxQeyOExY7QpttkZnwhhRThKdnrd7raxI0YArEDItpT4JlUOp01oioXuwoqykyASmkBldAgODTLYbQGfwtUL15ddPJDqQaNf-u4yav5k2zjDVWukMSqHEc1mJabaJGmvr6LLQGEEohyZjHNtnALB1YnTthEIoK_HMpDSY1hwJXVtUaVJnhO4N8pfmf1zXyhG6T5lj7lz5WnQV7GVJ6F6gMdoQumkD-KIIXc-9he59eH96LZQ3xDsS77og61n0ei786R8Oe7s0rvZ6rzmat8M0efecP3Sqq_IdkXT17jDh8n4UQteuO9BecxcHVXofyHaX3zPA_7LkKfQLKjSC31KkM4y6rYzmmNYGocns4dgAXCvHhLLNs98yStqO9f2cdyodtJYrDGLrwfoOQ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