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

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 09:44:50 PDT 2026


================
@@ -690,6 +753,8 @@ StmtResult SemaSYCL::BuildSYCLKernelCallStmt(FunctionDecl *FD,
       getASTContext().getSYCLKernelInfo(SKEPAttr->getKernelName());
   assert(declaresSameEntity(SKI.getKernelEntryPointDecl(), FD) &&
          "SYCL kernel name conflict");
+  if (verifyKernelArguments(FD, *this))
+    return StmtError();
----------------
Fznamznon wrote:

I don't think so. The fail I see is that if the subobject visitation moved there, it fails for the following test
```
 // A unique kernel name type is required for each declared kernel entry point.
 template<int, int = 0> struct KN;

 // A generic kernel object type.
 template<int, int = 0>
 struct KT {
   void operator()() const;
 };


 // sycl_kernel_launch as function template at namespace scope.
 namespace ok1 {
   template<typename KN, typename... Ts>
   void sycl_kernel_launch(const char *, Ts...);
   [[clang::sycl_kernel_entry_point(KN<1>)]]
   void skep(KT<1> k) {
     k();
   }
 }
```
Because `KT<1>` is not yet defined fully. At this point. I did put it here:
```
 void SemaSYCL::CheckSYCLExternalFunctionDecl(FunctionDecl *FD) {                          
   const auto *SEAttr = FD->getAttr<SYCLExternalAttr>();                                   
   assert(SEAttr && "Missing sycl_external attribute");                                    
@@ -419,6 +517,8 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {     
              diag::note_previous_declaration);                                            
         SKEPAttr->setInvalidAttr();                                                       
       }                                                                                   
+    } else if (verifyKernelArguments(FD, *this)) {                                        
+      SKEPAttr->setInvalidAttr();                                                         
     } else {                                                                              
       getASTContext().registerSYCLEntryPointFunction(FD);                                 
     }                                                                                     
@@ -666,100 +766,6 @@ OutlinedFunctionDecl *BuildSYCLKernelEntryPointOutline(Sema &SemaRef,
   return OFD;                                                                             
 }                                                                                         
```
So FD is not templated but probably not fully instantiated yet.

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


More information about the cfe-commits mailing list