[clang] [clang][SYCL] Add additional Sema rules for SYCL kernel parameters (PR #208571)
Ian Li via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 5 16:56:35 PDT 2026
ianayl wrote:
**Changes to diagnostic from this PR:**
Changes to references:
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:29:12: error: 'int &' type cannot be used in a SYCL kernel parameter because it is a reference type
29 | &p, q,
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:25:3: note: in instantiation of function template specialization 'badref1::kernel_single_task<KN<1>, (lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:26:7)>' requested here
25 | kernel_single_task<class KN<1>>(
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:26:7: note: within capture 'p' of lambda expression here
26 | [ // expected-note{{within capture 'p' of lambda expression here}}
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:18:25: note: within parameter 't' of type '(lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:26:7)' declared here
18 | void kernel_single_task(T t) {} // expected-note-re 2{{within parameter 't' of type '(lambda at {{.*}})' declared here}}
| ^
```
New atomic diagnostics:
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:204:15: error: '_Atomic(int)' type cannot be used in a SYCL kernel parameter because it is an atomic type
204 | _Atomic int b;
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:233:3: note: in instantiation of function template specialization 'atomic1::kernel_single_task<KN<17>, (lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:233:36)>' requested here
233 | kernel_single_task<class KN<17>>([=]{ (void)s; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:202:8: note: within field of type 'Sa' declared here
202 | struct Sa {
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:233:36: note: within capture 's' of lambda expression here
233 | kernel_single_task<class KN<17>>([=]{ (void)s; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:198:25: note: within parameter 't' of type '(lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:233:36)' declared here
198 | void kernel_single_task(T t) {}
|
```
New diagnostics for classes with flexible array members:
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:261:7: error: 'FAM' type cannot be used in a SYCL kernel parameter because it contains a flexible array member
261 | FAM fam;
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:270:3: note: in instantiation of function template specialization 'fam1::kernel_single_task<KN<21>, fam1::Kernel>' requested here
270 | kernel_single_task<class KN<21>>(Kernel{});
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:256:7: note: flexible array member 'b' of 'FAM' defined here
256 | int b[]; // expected-note {{flexible array member 'b' of 'FAM' defined here}}
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:253:8: note: within field of type 'FAM' declared here
253 | struct FAM {
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:259:7: note: within field of type 'Kernel' declared here
259 | class Kernel {
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:250:25: note: within parameter 't' of type 'fam1::Kernel' declared here
250 | void kernel_single_task(T t) {}
|
```
New warning for pointers upon `-Wnonportable-sycl`:
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:306:47: warning: pointers used in parameters to a SYCL kernel require a device that supports Unified Shared Memory (USM) [-Wnonportable-sycl]
306 | kernel_single_task<class KN<25>>([=]{ (void)ptr; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:306:3: note: in instantiation of function template specialization 'nonportable1::kernel_single_task<KN<25>, (lambda at clang/test/SemaSYCL/sycl-kernel-par
am-restrictions.cpp:306:36)>' requested here
306 | kernel_single_task<class KN<25>>([=]{ (void)ptr; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:306:36: note: within capture 'ptr' of lambda expression here
306 | kernel_single_task<class KN<25>>([=]{ (void)ptr; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:281:25: note: within parameter 't' of type '(lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:306:36)' declared here
281 | void kernel_single_task(T t) {}
|
```
New diagnostics for virtual base classes:
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:369:47: error: 'Derived' type cannot be used in a SYCL kernel parameter because it inherits a virtual base class
369 | kernel_single_task<class KN<29>>([=]{ (void)d; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:369:3: note: in instantiation of function template specialization 'vbase1::kernel_single_task<KN<29>, (lambda at clang/test/SemaSYCL/sycl-kernel-param-res
trictions.cpp:369:36)>' requested here
369 | kernel_single_task<class KN<29>>([=]{ (void)d; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:346:25: note: 'Derived' inherits virtual base class 'Base' specified here
346 | class Derived : virtual Base { // expected-note {{'Derived' inherits virtual base class 'Base' specified here}}
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:369:36: note: within capture 'd' of lambda expression here
369 | kernel_single_task<class KN<29>>([=]{ (void)d; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:334:25: note: within parameter 't' of type '(lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:369:36)' declared here
334 | void kernel_single_task(T t) {}
| ^
```
```
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:374:47: error: 'Diamond' type cannot be used in a SYCL kernel parameter because it inherits a virtual base class
374 | kernel_single_task<class KN<30>>([=]{ (void)ab; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:374:3: note: in instantiation of function template specialization 'vbase1::kernel_single_task<KN<30>, (lambda at clang/test/SemaSYCL/sycl-kernel-param-res
trictions.cpp:374:36)>' requested here
374 | kernel_single_task<class KN<30>>([=]{ (void)ab; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:351:26: note: 'Diamond' inherits virtual base class 'Base' specified here
351 | class A : public virtual Base { // expected-note {{'Diamond' inherits virtual base class 'Base' specified here}}
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:374:36: note: within capture 'ab' of lambda expression here
374 | kernel_single_task<class KN<30>>([=]{ (void)ab; });
| ^
clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:334:25: note: within parameter 't' of type '(lambda at clang/test/SemaSYCL/sycl-kernel-param-restrictions.cpp:374:36)' declared here
334 | void kernel_single_task(T t) {}
|
```
https://github.com/llvm/llvm-project/pull/208571
More information about the cfe-commits
mailing list