Skip to content

Commit ef3ca91

Browse files
committed
Diagnose special types in structs since they are not yet supported.
1 parent f9a1641 commit ef3ca91

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

clang/test/SemaSYCL/free_function_kernel_params_restrictions.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ __attribute__((sycl_device))
4040
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
4141
void ff_5(A S1) {
4242
}
43+
44+
45+
46+
struct StructWithAccessor {
47+
sycl::accessor<char, 1, sycl::access::mode::read> acc;
48+
int *ptr;
49+
};
50+
51+
struct Wrapper {
52+
StructWithAccessor SWA;
53+
54+
};
55+
56+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
57+
void ff_6(Wrapper S1) { // expected-error {{cannot be used as the type of a kernel parameter}}
58+
}

0 commit comments

Comments
 (0)