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" <[email protected]>
Date: Mon, 16 Nov 2026 19:28:18 +0100
Subject: [PATCH] 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'}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to