[clang] [clang] Fallback to C calling convention for sycl_kernel attribute (PR #161349)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 30 03:27:42 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (camc)

<details>
<summary>Changes</summary>

Resolves #<!-- -->161077

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/161349.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/CodeGen/TargetInfo.cpp (+2-1) 
- (added) clang/test/CodeGen/sycl-kernel.c (+5) 


``````````diff
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;
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/161349


More information about the cfe-commits mailing list