<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/140046>140046</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Error using <type_traits> header in OpenCL kernel compilation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          davidrohr
      </td>
    </tr>
</table>

<pre>
    The clang OpenCL documentation says I can use the `<type_traits>` header from the libcxx header in OpenCL. (https://clang.llvm.org/docs/OpenCLSupport.html)
I tried that with clang 19.1.7 and with 20.1.4, and in both cases I am facing 3 problems:

The kernel I am trying to compile is the example from the documentation:
```
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
#pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable
#include <type_traits>
#pragma OPENCL EXTENSION __cl_clang_function_pointers : disable
#pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable

using sint_type = std::make_signed<unsigned int>::type;

__kernel void foo() {
 static_assert(!std::is_same<sint_type, unsigned int>::value);
}
```

1.
I am getting from `clang++ -x cl -cl-std=CLC++2021 -o test -I[libcxx_path]/include/c++/v1/ --target=spirv64v1.2 -c test.clcpp`:
```
 
In file included from test.clcpp:3:
In file included from /usr/include/c++/v1/type_traits:420:
/usr/include/c++/v1/__config:829:8: error: "No thread API"
  829 | #      error "No thread API"
      | ^
```

It seems it needs a thread API, which is not available for OpenCL.

2.
I patched away that check in `__config`, and then it failed with

```
In file included from /usr/lib/llvm/20/bin/../../../../lib/clang/20/include/stdint.h:56:
/usr/include/stdint.h:82:15: error: typedef redefinition with different types ('int' vs 'long')
   82 | typedef int                     intptr_t;
      | ^
/usr/lib/llvm/20/bin/../../../../lib/clang/20/include/opencl-c-base.h:158:25: note: previous definition is here
  158 | typedef __INTPTR_TYPE__ intptr_t;
```

So it seems it works, but the definitions in the headers for C and OpenCL do not match.
I could compile it in the end by adding the -cl-no-stdinc option, but I am wondering if this could not be fixed.

3.
The documentation says I should use `-I<path to libcxx checkout or installation>/include`, but with that it doesn't even find `<type_traits>`, so By using the actual path to `<type_traits>` in my command line, it worked..

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVt1u6roSfhpzMyJKbAL0ggtKQUJa6qrO6sU5V5FjD8Snjh3ZDi1vv2Un0P-9trRXhNI0mRnPzPfND_deHQ3iipS3pLyb8D401q0kPynpbOMmtZXn1WODIDQ3R_jZodn8AGlF36IJPChrwPOzhz0IbqD3CKFBIPOcsE04d1gFx1XwhG3JPIcGuUQHB2fbJKdVLV5eLq-VGQ_IgNBlE0LnCVsTuiN0l87PtD61mXVHQnfSCk_oblD41XeddSFrQqsJvSH5eg_BKZQQGh7gWYVmjKC4yYpsAdzI4S3NsyKbEbpJr5SB2kZZ7jHGxFs4cKHMERh0ztYa2-RSHn8xLU_oDOpBMrhzlAwWhG07pRGUT1HiC287ja9hv8vfaG-ej798TSjrHD-2HH4-bO83P2D738ft_a_9z3uoKqGrFEl16I2I-lVnlQnoPBC2BjS81viPjZy4U1wqcbX22YoyQvcS4TOg_85TqfyfcPWNmXzd-4iAVyZU0Vcg7A58kDHFbN3yJ6wS3yVhm94Mj6BMiMEkkahE2O1grKpGdE9WSThYS-iS0BsgiygAPsInKu49upA-FdejlK88b5GwzdWXSLEvzzxx3WMk7XDu4u4jG_J1kSVG8xaOGEIMMVGJzPOUGkJvCb2F6QsIDVOhp8mPu82PzfCF5rSAqYWAPsB0T8rboe6qjoeGlHeE7kaQY6ENOoTuTgWhO5hOA3dHDITd-U6503x2KjIKU5HMZUKLrkvl_pHFEH02cEiFMJiXYwm8KrI1GzS_liR013v3d_69o-R6Ri-O_FaxqoQ1B3UkbL2MyV8vE_Gdsy4-EErvLYTGIZewftgTSmNMsEwE2AChDNKVNL4Vj1cSL7efYd0H8IitBxXAIEoP_J2JDTw3SjSxjRgbgJ-40pHrcLDu0ikHS3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