[clang] [clang][SYCL] Diagnose reference kernel parameters (PR #192957)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 08:50:46 PDT 2026


================
@@ -665,6 +666,109 @@ OutlinedFunctionDecl *BuildSYCLKernelEntryPointOutline(Sema &SemaRef,
   return OFD;
 }
 
+class KernelParamsChecker : public ConstSubobjectVisitor<KernelParamsChecker> {
+  SemaSYCL &SemaSYCLRef;
+  bool IsValid = true;
+  using ObjectAccess =
+      llvm::PointerUnion<const ParmVarDecl *, const CXXBaseSpecifier *,
+                         const FieldDecl *>;
+  SmallVector<ObjectAccess, 4> ObjectAccessPath;
+
+  void emitObjectAccessPathNotes() {
+    for (auto Parent : ObjectAccessPath) {
----------------
Fznamznon wrote:

Fixed in e7945ef4c60af00f71fce0a509baf35423c700f8 
Using my experiment sample https://github.com/llvm/llvm-project/pull/192957#discussion_r3334114437 the diagnostics now look like
```
$ clang -cc1 -fsycl-is-device -emit-llvm -triple spirv64-unknown-unknown -aux-triple x86_64-linux src.cpp -Wall -std=c++17
In file included from src.cpp:1:
./h1.h:3:8: error: 'int &' cannot be used as the type of a kernel parameter
    3 |   int &dm;
      |        ^
./h2.h:6:3: note: in instantiation of function template specialization 'single_task<KN, KT>' requested here
    6 |   single_task<KN>(k);
      |   ^
src.cpp:7:3: note: in instantiation of function template specialization 'submit_kernel<KN, KT>' requested here
    7 |   submit_kernel<struct KN>(k);
      |   ^
./h1.h:2:8: note: within field of type 'S' declared here
    2 | struct S {
      |        ^
./h1.h:5:8: note: within field of type 'KT' declared here
    5 | struct KT {
      |        ^
./sycl.hpp:3:18: note: within parameter 't' of type 'KT' declared here
    3 | void single_task(T t) {}
      |                  ^
1 error generated.
```

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


More information about the cfe-commits mailing list