@@ -2067,11 +2067,21 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
20672067 return true ;
20682068 }
20692069
2070- bool leaveStruct (const CXXRecordDecl *, ParmVarDecl *, QualType) final {
2070+ bool leaveStruct (const CXXRecordDecl *, ParmVarDecl *PD,
2071+ QualType ParamTy) final {
20712072 // TODO manipulate struct depth once special types are supported for free
20722073 // function kernels.
20732074 // --StructFieldDepth;
2074- return true ;
2075+ // TODO We don't yet support special types and therefore structs that
2076+ // require decomposition and leaving/entering. Diagnose for better user
2077+ // experience.
2078+ CXXRecordDecl *RD = ParamTy->getAsCXXRecordDecl ();
2079+ if (RD->hasAttr <SYCLRequiresDecompositionAttr>()) {
2080+ Diag.Report (PD->getLocation (), diag::err_bad_kernel_param_type)
2081+ << ParamTy;
2082+ IsInvalid = true ;
2083+ }
2084+ return isValid ();
20752085 }
20762086
20772087 bool enterStruct (const CXXRecordDecl *, const CXXBaseSpecifier &BS,
@@ -2177,8 +2187,9 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
21772187 }
21782188
21792189 bool handleSyclSpecialType (ParmVarDecl *, QualType) final {
2180- // TODO
2181- unsupportedFreeFunctionParamType ();
2190+ // TODO We don't support special types in free function kernel parameters,
2191+ // but track them to diagnose the case properly.
2192+ CollectionStack.back () = true ;
21822193 return true ;
21832194 }
21842195
@@ -2219,9 +2230,7 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
22192230 }
22202231
22212232 bool enterStruct (const CXXRecordDecl *, ParmVarDecl *, QualType) final {
2222- // TODO handle decomposition once special type arguments are supported
2223- // for free function kernels.
2224- // CollectionStack.push_back(false);
2233+ CollectionStack.push_back (false );
22252234 PointerStack.push_back (false );
22262235 return true ;
22272236 }
@@ -2252,15 +2261,13 @@ class SyclKernelDecompMarker : public SyclKernelFieldHandler {
22522261 QualType ParamTy) final {
22532262 CXXRecordDecl *RD = ParamTy->getAsCXXRecordDecl ();
22542263 assert (RD && " should not be null." );
2255- // TODO handle decomposition once special type arguments are supported
2256- // for free function kernels.
2257- // if (CollectionStack.pop_back_val()) {
2258- // if (!RD->hasAttr<SYCLRequiresDecompositionAttr>())
2259- // RD->addAttr(SYCLRequiresDecompositionAttr::CreateImplicit(
2260- // SemaSYCLRef.getASTContext()));
2261- // CollectionStack.back() = true;
2262- // PointerStack.pop_back();
2263- if (PointerStack.pop_back_val ()) {
2264+ if (CollectionStack.pop_back_val ()) {
2265+ if (!RD->hasAttr <SYCLRequiresDecompositionAttr>())
2266+ RD->addAttr (SYCLRequiresDecompositionAttr::CreateImplicit (
2267+ SemaSYCLRef.getASTContext ()));
2268+ CollectionStack.back () = true ;
2269+ PointerStack.pop_back ();
2270+ } else if (PointerStack.pop_back_val ()) {
22642271 PointerStack.back () = true ;
22652272 if (!RD->hasAttr <SYCLGenerateNewTypeAttr>())
22662273 RD->addAttr (SYCLGenerateNewTypeAttr::CreateImplicit (
@@ -2864,7 +2871,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
28642871
28652872 bool enterStruct (const CXXRecordDecl *, ParmVarDecl *, QualType) final {
28662873 // TODO
2867- unsupportedFreeFunctionParamType () ;
2874+ // ++StructDepth ;
28682875 return true ;
28692876 }
28702877
@@ -2875,7 +2882,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
28752882
28762883 bool leaveStruct (const CXXRecordDecl *, ParmVarDecl *, QualType) final {
28772884 // TODO
2878- unsupportedFreeFunctionParamType () ;
2885+ // --StructDepth ;
28792886 return true ;
28802887 }
28812888
@@ -5534,8 +5541,8 @@ void SemaSYCL::ProcessFreeFunction(FunctionDecl *FD) {
55345541 DiagnosingSYCLKernel = true ;
55355542
55365543 // Check parameters of free function.
5537- Visitor.VisitFunctionParameters (FD, FieldChecker, UnionChecker ,
5538- DecompMarker );
5544+ Visitor.VisitFunctionParameters (FD, DecompMarker, FieldChecker ,
5545+ UnionChecker );
55395546
55405547 DiagnosingSYCLKernel = false ;
55415548
0 commit comments