Skip to content

[libc++][HIP] call to 'sqrt' is ambiguous in lambda functions #119076

Open
@AngryLoki

Description

@AngryLoki

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++:

#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 ROCm/clr#100. But after applying fix for clr the issue is reproducible with newer versions of clang:

$ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:headersHeaders provided by Clang, e.g. for intrinsics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions