https://github.com/camc created https://github.com/llvm/llvm-project/pull/161349
Resolves #GH161077. Fixes a crash. Let the device kernel calling convention be C when not compiling OpenCL. `sycl_kernel` in this context then has no effect, as expected. >From bfa6759c6303828d8c8bc8a5342a60036a1280d8 Mon Sep 17 00:00:00 2001 From: camc <[email protected]> Date: Tue, 30 Sep 2025 10:22:42 +0000 Subject: [PATCH] [clang] Fallback to C callingconv for sycl_kernel attribute. (#GH161077) --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/CodeGen/TargetInfo.cpp | 3 ++- clang/test/CodeGen/sycl-kernel.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/sycl-kernel.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e8deae50e4cb0..74580b77353d5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -397,6 +397,7 @@ Bug Fixes to Attribute Support - Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with ``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520) - Fix a crash when the function name is empty in the `swift_name` attribute. (#GH157075) +- Fix a crash when the ``sycl_kernel`` attribute is used while not compiling OpenCL (#GH161077). Bug Fixes to C++ Support ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 1e58c3f217812..4ff847f4f6ff6 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -123,8 +123,9 @@ unsigned TargetCodeGenInfo::getDeviceKernelCallingConv() const { // conventions; different targets might split structs passed as values // to multiple function arguments etc. return llvm::CallingConv::SPIR_KERNEL; + } else { + return llvm::CallingConv::C; } - llvm_unreachable("Unknown kernel calling convention"); } void TargetCodeGenInfo::setOCLKernelStubCallingConvention( diff --git a/clang/test/CodeGen/sycl-kernel.c b/clang/test/CodeGen/sycl-kernel.c new file mode 100644 index 0000000000000..77410e5a216ff --- /dev/null +++ b/clang/test/CodeGen/sycl-kernel.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -emit-llvm %s -o /dev/null + +__attribute__((sycl_kernel)) void foo(int *ret) { + *ret = 1; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
