Skip to content

Commit 34524f4

Browse files
committed
Incorportate review feedback
1 parent 4e293da commit 34524f4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ class KernelObjVisitor {
14521452
else if (ParamTy->isStructureOrClassType()) {
14531453
if (KF_FOR_EACH(handleStructType, Param, ParamTy)) {
14541454
CXXRecordDecl *RD = ParamTy->getAsCXXRecordDecl();
1455-
visitRecord(RD, Param, RD, ParamTy, Handlers...);
1455+
visitRecord(nullptr, Param, RD, ParamTy, Handlers...);
14561456
}
14571457
} else if (ParamTy->isUnionType())
14581458
KP_FOR_EACH(handleOtherType, Param, ParamTy);
@@ -1980,7 +1980,11 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
19801980

19811981
// Check that the type is defined at namespace scope.
19821982
const DeclContext *DeclCtx = RD->getDeclContext();
1983-
if (!DeclCtx->isTranslationUnit() && !isa<NamespaceDecl>(DeclCtx)) {
1983+
while (!DeclCtx->isTranslationUnit() &&
1984+
(isa<NamespaceDecl>(DeclCtx) || isa<LinkageSpecDecl>(DeclCtx)))
1985+
DeclCtx = DeclCtx->getParent();
1986+
1987+
if (!DeclCtx->isTranslationUnit()) {
19841988
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
19851989
<< ParamTy;
19861990
IsInvalid = true;
@@ -3017,13 +3021,13 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
30173021

30183022
bool handleNonDecompStruct(const CXXRecordDecl *RD, ParmVarDecl *PD,
30193023
QualType ParamTy) final {
3020-
// This is a field which should not be decomposed.
3021-
CXXRecordDecl *FieldRecordDecl = ParamTy->getAsCXXRecordDecl();
3022-
assert(FieldRecordDecl && "Type must be a C++ record type");
3024+
// This is a struct parameter which should not be decomposed.
3025+
CXXRecordDecl *ParamRecordDecl = ParamTy->getAsCXXRecordDecl();
3026+
assert(ParamRecordDecl && "Type must be a C++ record type");
30233027
// Check if we need to generate a new type for this record,
30243028
// i.e. this record contains pointers.
3025-
if (FieldRecordDecl->hasAttr<SYCLGenerateNewTypeAttr>())
3026-
addParam(PD, GenerateNewRecordType(FieldRecordDecl));
3029+
if (ParamRecordDecl->hasAttr<SYCLGenerateNewTypeAttr>())
3030+
addParam(PD, GenerateNewRecordType(ParamRecordDecl));
30273031
else
30283032
addParam(PD, ParamTy);
30293033
return true;

clang/test/SemaSYCL/free_function_kernel_params_restrictions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ void bar() {
2929
auto Glob = [](int P){ return P + 1;};
3030

3131
template void ff_6(typeof(Glob) S1);
32+
33+
extern "C" {
34+
struct A {
35+
int a;
36+
};
37+
}
38+
39+
__attribute__((sycl_device))
40+
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
41+
void ff_5(A S1) {
42+
}

0 commit comments

Comments
 (0)