[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:39:47 PDT 2025
https://github.com/camc updated https://github.com/llvm/llvm-project/pull/161349
>From acaf93238a19bfbe6b6e1a6be59673691564305d Mon Sep 17 00:00:00 2001
From: camc <pushy-crop-cartel at duck.com>
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;
+}
More information about the cfe-commits
mailing list