[clang] [clang][SYCL] Fix crash on `sycl_kernel_entry_point` with incomplete parameter type (PR #243185)
Daniel Skrobot via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 18 02:47:48 PST 2026
https://github.com/dyniols updated https://github.com/llvm/llvm-project/pull/243185
>From 4188516697522d260052e528e082743e2e7db462 Mon Sep 17 00:00:00 2001
From: "Skrobot, Daniel" <daniel.skrobot at intel.com>
Date: Mon, 16 Nov 2026 19:28:18 +0100
Subject: [PATCH 1/2] Fix crash on sycl_kernel_entry_point with incomplete
parameter type
---
clang/lib/Sema/SemaSYCL.cpp | 14 ++++++--
...rnel-entry-point-attr-incomplete-param.cpp | 34 +++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
create mode 100644 clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp
index 56675ee9f2d107..77ac225aebb86a 100644
--- a/clang/lib/Sema/SemaSYCL.cpp
+++ b/clang/lib/Sema/SemaSYCL.cpp
@@ -717,12 +717,22 @@ class KernelParamsChecker : public ConstSubobjectVisitor<KernelParamsChecker> {
SemaSYCLRef(SR) {}
void checkParameter(const ParmVarDecl *PVD) {
+ QualType ParamTy = PVD->getType();
+ if (PVD->isInvalidDecl() ||
+ (ParamTy->isReferenceType() &&
+ SemaSYCLRef.SemaRef.RequireCompleteType(
+ PVD->getLocation(), ParamTy.getNonReferenceType(),
+ diag::err_typecheck_decl_incomplete_type))) {
+ IsValid = false;
+ return;
+ }
+
ObjectAccessPath.push_back(PVD);
// Check the immediate type of the parameter.
- if (checkType(PVD->getType())) {
+ if (checkType(ParamTy)) {
// If type checking wasn't short circuited, visit subobjects to check
// them.
- visit(PVD->getType());
+ visit(ParamTy);
}
ObjectAccessPath.pop_back();
assert(ObjectAccessPath.empty());
diff --git a/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp b/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
new file mode 100644
index 00000000000000..c362ffa37b1cf2
--- /dev/null
+++ b/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -fsyntax-only -fsycl-is-host -verify %s
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -std=c++17 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -fsyntax-only -fsycl-is-host -verify %s
+// RUN: %clang_cc1 -triple spirv64-unknown-unknown -std=c++20 -fsyntax-only -fsycl-is-device -verify %s
+
+// Test that sycl_kernel_entry_point functions with parameters of incomplete
+// type, or reference parameters that refer to incomplete types, are diagnosed
+// rather than crashing the compiler.
+
+template<int> struct KN;
+
+template<typename KernelName, typename... Ts>
+void sycl_kernel_launch(const char *, Ts &&...) {}
+
+struct S1; // expected-note 6{{forward declaration of 'S1'}}
+struct S2 { int val; };
+
+[[clang::sycl_kernel_entry_point(KN<1>)]]
+void bad1(S1) {} // expected-error {{variable has incomplete type 'S1'}}
+
+[[clang::sycl_kernel_entry_point(KN<2>)]]
+void bad2(S1 &) {} // expected-error {{variable has incomplete type 'S1'}}
+
+[[clang::sycl_kernel_entry_point(KN<3>)]]
+void bad3(S1 &&) {} // expected-error {{variable has incomplete type 'S1'}}
+
+[[clang::sycl_kernel_entry_point(KN<4>)]]
+void bad4(const S1 &) {} // expected-error {{variable has incomplete type 'const S1'}}
+
+[[clang::sycl_kernel_entry_point(KN<5>)]]
+void bad5(S2, S1 &) {} // expected-error {{variable has incomplete type 'S1'}}
+
+[[clang::sycl_kernel_entry_point(KN<6>)]]
+void bad6(S1 &, int = 0) {} // expected-error {{variable has incomplete type 'S1'}}
>From 7dbfdbc6b8ee3ba0c84bf4021b124f294bf956c1 Mon Sep 17 00:00:00 2001
From: "Skrobot, Daniel" <daniel.skrobot at intel.com>
Date: Wed, 18 Nov 2026 11:46:54 +0100
Subject: [PATCH 2/2] add strange edge case to test
---
.../sycl-kernel-entry-point-attr-incomplete-param.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp b/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
index c362ffa37b1cf2..27a71e993c9bae 100644
--- a/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
+++ b/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-incomplete-param.cpp
@@ -15,6 +15,13 @@ void sycl_kernel_launch(const char *, Ts &&...) {}
struct S1; // expected-note 6{{forward declaration of 'S1'}}
struct S2 { int val; };
+[[clang::sycl_external]]
+[[clang::sycl_kernel_entry_point(KN<0>)]]
+void ok0(S1 &);
+void test_ok0(S1 &s) {
+ ok0(s);
+}
+
[[clang::sycl_kernel_entry_point(KN<1>)]]
void bad1(S1) {} // expected-error {{variable has incomplete type 'S1'}}
More information about the cfe-commits
mailing list