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

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 13:47:50 PDT 2026


================
@@ -665,6 +666,101 @@ OutlinedFunctionDecl *BuildSYCLKernelEntryPointOutline(Sema &SemaRef,
   return OFD;
 }
 
+class KernelArgsChecker : public SubobjectVisitor<KernelArgsChecker> {
+  SemaSYCL &SemaSYCLRef;
+  bool IsValid = true;
+  using ObjectAccess =
+      llvm::PointerUnion<ParmVarDecl *, CXXBaseSpecifier *, FieldDecl *>;
+  SmallVector<ObjectAccess, 4> ObjectAccessPath;
+
+  void emitObjectAccessPathNotes() {
+    for (auto Parent : ObjectAccessPath) {
+      if (auto *FD = Parent.dyn_cast<FieldDecl *>()) {
+        SemaSYCLRef.Diag(FD->getParent()->getLocation(),
+                         diag::note_within_field_of_type)
+            << FD->getParent();
+      } else if (auto *BS = Parent.dyn_cast<CXXBaseSpecifier *>()) {
+        CXXRecordDecl *RD = BS->getType()->getAsCXXRecordDecl();
+        assert(RD);
+        SemaSYCLRef.Diag(BS->getBeginLoc(), diag::note_within_base_of_type)
+            << RD;
+      } else {
+        // Nothing to emit for ParmVarDecl since its location just points to
+        // skep-attributed function template.
----------------
bader wrote:

For what it’s worth, C++ compilers already emit diagnostic notes for system libraries like the STL when template instantiation is semantically incorrect (e.g., https://godbolt.org/z/rqPrfdoxq).

I agree with @Fznamznon that notes related to template specializations in SYCL headers are often of limited usefulness. However, that alone may not be sufficient justification for deviating from standard C++ behavior.

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


More information about the cfe-commits mailing list