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

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 26 21:57:34 PDT 2026


https://github.com/tahonermann requested changes to this pull request.

I expect to have numerous uses for the subobject visitor. Some of these include:
- Identifying subobject types that require special handling for kernel marshaling purposes.
- Diagnosing kernel parameters that don't satisfy the SYCL device copyable requirements (long the lines of what this PR does for references).
- Potentially providing a builtin function or attribute for the SYCL RT to use to opt-in to diagnostics for a particular type. By default, diagnostics for invalid SYCL kernel parameters will be issued with references to the `sycl_kernel_entry_point` attributed function which isn't particularly meaningful for general SYCL programmers. The FE can produce much better diagnostics than the SYCL RT can. Allowing the SYCL RT to tag a parameter of a SYCL kernel invocation function as one that requires a device copyable type would allow a diagnostic to be issued where a SYCL user expects.
- Potentially providing a builtin function for the SYCL RT that can be used to query whether a type satisfies the SYCL device copyable requirements. The intent behind such a builtin would be for the SYCL RT to use it for SFINAE purposes. I'm failing to remember the specific potential use cases that prompted this idea at the moment though.
- Potentially providing the extension we've discussed to implicitly act as though `sycl::is_device_copyable_v<T>` is true for a type that would be device copyable accept that it has a subobject X that is not implicitly device copyable but for which `sycl::is_device_copyable_v<X>` is true.

I expect to find more uses later too. I think there is potential for other offload languages to want such a visitor as well; I think it might be useful to implement a standardized device copyable trait in a future paper like https://wg21.link/p3960r0.

All that to say, I would ideally like the following as part of making the visitor more accessible for other uses.
1) Write the visitor in the CRTP form used for `RecursiveASTVisitor` and most other AST visitors.
2) Move the `SubobjectVisitor` class to its own `clang/include/clang/AST/SubobjectVisitor.h` header file.

What was the motivation for separating visitation of base classes from data members? My intuition leads me towards a depth first visitation pattern that, given a type `T`, visits the first base class subobject, then the base classes of that base class, then the first data member of the base class, then its case classes, and so on. In other words, I was thinking that `SubobjectVisitor` would have just a single `VisitSubobjects(QualType)` public member.

For most consumers (e.g., derived classes for a CRTP design), I think only two functions would be needed to actually visit the subobject nodes.
- `bool VisitBaseClass(CXXBaseSpecifier*);`
- `bool VisitField(FieldDecl*);` (includes lambda captures stored as data members)

To support capturing the visitation path (required for issuing the equivalent of an instantiation stack), `TraverseX` and `WalkUpFromX` functions can be overridden (see the comment preceding the definition of `RecursiveASTVisitor`). This would provide the equivalent of the `enterX()` and `leaveX()` member functions.

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


More information about the cfe-commits mailing list