Issue |
140046
|
Summary |
Error using <type_traits> header in OpenCL kernel compilation
|
Labels |
new issue
|
Assignees |
|
Reporter |
davidrohr
|
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..
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs