<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119076>119076</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++][HIP] `call to 'sqrt' is ambiguous` in lambda functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
AngryLoki
</td>
</tr>
</table>
<pre>
Here is the problematic HIP code (i. e. code is heavily affected by `__clang_hip_runtime_wrapper.h`), which compiles with libstdc++, but fails with libc++:
```c++
#include <cmath>
// This works both with libstdc++ and libc++
long double f1(long double arg) {
return std::sqrt(arg);
}
// This fails with libc++
void f2() {
auto f3 = [](long double arg) -> long double { return std::sqrt(arg); };
}
```
This code on godbolt: https://godbolt.org/z/jds86rzK9. Note that there it uses clang-17, as hip after that is affected by https://github.com/ROCm/clr/issues/100. But after applying fix for clr the issue is reproducible with newer versions of clang:
```sh
$ clang-19 -x hip test.cpp -S -nogpulib -stdlib=libstdc++
# Ok!
$ clang-19 -x hip test.cpp -S -nogpulib -stdlib=libc++
test.cpp:8:59: error: call to 'sqrt' is ambiguous
8 | auto f3 = [](long double arg) -> long double { return std::sqrt(arg); };
| ^~~~~~~~~
/usr/lib/llvm/19/bin/../../../../lib/clang/19/include/__clang_cuda_math_forward_declares.h:172:19: note: candidate function
172 | __DEVICE__ double sqrt(double);
| ^
/usr/lib/llvm/19/bin/../../../../lib/clang/19/include/__clang_hip_cmath.h:250:19: note: candidate function
250 | __DEF_FUN1(float, sqrt)
| ^
1 error generated when compiling for gfx906.
```
This affects other functions from `cmath` (sqrt/cbrt/hypot/isinf). Using `sqrtl` works, but this is not a solution for a templated code, and there is no functions like `isinfl`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vl1v2zYU_TX0y4UFirK-Hvzg2BESbGiLbd2rQJGUxYYmVZKK4z7stw-k7MRpgnUYsAaC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