Skip to content

Commit 643bc94

Browse files
Add Visitor method to handle template parameter pack in kernel names
1 parent 55d4311 commit 643bc94

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,11 @@ class SYCLKernelNameTypeVisitor
28382838
ConstTemplateArgumentVisitor<SYCLKernelNameTypeVisitor>;
28392839
bool IsInvalid = false;
28402840

2841+
void VisitTemplateArgs(ArrayRef<TemplateArgument> Args) {
2842+
for (size_t I = 0, E = Args.size(); I < E; ++I)
2843+
Visit(Args[I]);
2844+
}
2845+
28412846
public:
28422847
SYCLKernelNameTypeVisitor(Sema &S, SourceLocation KernelInvocationFuncLoc)
28432848
: S(S), KernelInvocationFuncLoc(KernelInvocationFuncLoc) {}
@@ -2849,19 +2854,18 @@ class SYCLKernelNameTypeVisitor
28492854
return;
28502855
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
28512856
if (!RD) {
2852-
if (T->isNullPtrType())
2857+
if (T->isNullPtrType()) {
28532858
S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named)
28542859
<< /* kernel name cannot be a type in the std namespace */ 3;
2855-
IsInvalid = true;
2860+
IsInvalid = true;
2861+
}
28562862
return;
28572863
}
28582864
// If KernelNameType has template args visit each template arg via
28592865
// ConstTemplateArgumentVisitor
28602866
if (const auto *TSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2861-
const TemplateArgumentList &Args = TSD->getTemplateArgs();
2862-
for (unsigned I = 0; I < Args.size(); I++) {
2863-
Visit(Args[I]);
2864-
}
2867+
ArrayRef<TemplateArgument> Args = TSD->getTemplateArgs().asArray();
2868+
VisitTemplateArgs(Args);
28652869
} else {
28662870
InnerTypeVisitor::Visit(T.getTypePtr());
28672871
}
@@ -2949,6 +2953,10 @@ class SYCLKernelNameTypeVisitor
29492953
VisitEnumType(ET);
29502954
}
29512955
}
2956+
2957+
void VisitPackTemplateArgument(const TemplateArgument &TA) {
2958+
VisitTemplateArgs(TA.getPackAsArray());
2959+
}
29522960
};
29532961

29542962
void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
@@ -3452,6 +3460,7 @@ void SYCLIntegrationHeader::emitForwardClassDecls(
34523460
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
34533461

34543462
if (!RD) {
3463+
34553464
return;
34563465
}
34573466

clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ class U;
1313
template <typename T>
1414
struct Templated_kernel_name;
1515

16+
template <typename T, typename... Args> class TemplParamPack;
17+
1618
using namespace cl::sycl;
1719
queue q;
1820

1921
int main() {
2022
#ifdef CHECK_ERROR
21-
// expected-error@Inputs/sycl.hpp:328 4 {{kernel name cannot be a type in the "std" namespace}}
23+
// expected-error@Inputs/sycl.hpp:328 5 {{kernel name cannot be a type in the "std" namespace}}
2224
q.submit([&](handler &h) {
2325
// expected-note@+1{{in instantiation of function template specialization}}
2426
h.single_task<std::nullptr_t>([=] {});
@@ -35,7 +37,10 @@ int main() {
3537
// expected-note@+1{{in instantiation of function template specialization}}
3638
h.single_task<Templated_kernel_name<std::U>>([=] {});
3739
});
38-
40+
q.submit([&](handler &cgh) {
41+
// expected-note@+1{{in instantiation of function template specialization}}
42+
cgh.single_task<TemplParamPack<int, float, std::nullptr_t, double>>([]() {});
43+
});
3944
#endif
4045

4146
// Although in the std namespace, these resolve to builtins such as `int` that are allowed in kernel names

clang/test/CodeGenSYCL/template-template-parameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-bb=%t.h -sycl-std=2020 %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -sycl-std=2020 %s
22
// RUN: FileCheck -input-file=%t.h %s
33

44
#include "Inputs/sycl.hpp"

0 commit comments

Comments
 (0)