<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61074>61074</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Name conflicts in math intrinsics lowering
</td>
</tr>
<tr>
<th>Labels</th>
<td>
crash,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vzakhari
</td>
</tr>
</table>
<pre>
Fortran user code may define interfaces with names conflicting with libm namespace, so Flang's math intrinsics lowering has issues whenever a math intrinsic is lowered into a libm call:
```
module decl
interface
real(c_double) function atan(x) bind(C)
use iso_c_binding
real(c_double),value :: x
end function atan
end interface
end module decl
subroutine test(x)
use decl
use iso_c_binding
real(c_double) :: x
x = atan(x)
end subroutine test
subroutine test2(x)
use iso_c_binding
real(c_double) :: x
x = atan(x)
end subroutine test2
```
Both `atan` references are resolved to the same name, which is incorrect.
```
$ bbc -math-runtime=precise bindc.f90 -emit-fir -o - | grep atan
%1 = fir.call @atan(%0) fastmath<contract> : (f64) -> f64
%1 = fir.call @atan(%0) fastmath<contract> : (f64) -> f64
func.func private @atan(f64) -> f64 attributes {fir.bindc_name = "atan"}
```
This is handled correctly, because the second `atan` is lowered into `math.atan`:
```
$ bbc -math-runtime=fast bindc.f90 -emit-fir -o - | grep atan
%1 = fir.call @atan(%0) fastmath<contract> : (f64) -> f64
%1 = math.atan %0 fastmath<contract> : f64
func.func private @atan(f64) -> f64 attributes {fir.bindc_name = "atan"}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVUFz8jYQ_TXisgMj1tiGgw8JlGNPvWdkaY3VyhIjySTpr--scRrKRzI9tJ0yjMEr7dPbfW-0KiV78kSNKJ9FeVioMfchNpff1W-9inbRBvPeHEPMUXkYE0XQwRAM6h0MddYTWJ8pdkpTglebe_BqoAQ6-M5Zna0_XcPOtsN17aw0CdxDCnB0yp8E1gkGlXuGitYnqxO48EqRk3uVwKY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