<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - CUDA fails to build on Windows with <complex> included due to missing __device__ signbit(long double)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50509">50509</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CUDA fails to build on Windows with <complex> included due to missing __device__ signbit(long double)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>CUDA
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>joachim@joameyer.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Following the libstdc++ 11 issue with <complex>, we added a test for that case
in hipSYCL and discovered another issue with Clang CUDA's complex on Windows.

You can see the failing build here:
<a href="https://github.com/illuhad/hipSYCL/runs/2666453501?check_suite_focus=true">https://github.com/illuhad/hipSYCL/runs/2666453501?check_suite_focus=true</a>
The error is:

```
C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\complex:565:16: error:
call to 'signbit' is ambiguous
        return (_STD signbit)(_Left);
               ^~~~~~~~~~~~~~
D:\a\hipSYCL\hipSYCL\install\lib\clang\11.1.0\include\__clang_cuda_cmath.h:137:17:
note: candidate function
__DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }
                ^
D:\a\hipSYCL\hipSYCL\install\lib\clang\11.1.0\include\__clang_cuda_cmath.h:138:17:
note: candidate function
__DEVICE__ bool signbit(double __x) { return ::__signbitd(__x); }
```

This was worked around on the hipSYCL side by providing a __device__ bool
std::signbit(long double) overload which just maps to its double counterpart,
as long double on GPUs is pretty non-sensical anyways...
namespace std {
__device__
  inline bool signbit(long double v) {return signbit(static_cast<double>(v));}
}

As I don't see a way to toggle using long double or not in the MS STL, I'd be
open to contributing a similar workaround for the Clang side but would like
some guidance on the correct approach.

Should we just add this overload blindly, add it for Windows only or even
exclusively when using the MS STL? (if so, do you have any idea how to detect
the MS STL is used?)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>