Skip to content

Commit 1271ba3

Browse files
authored
[SYCL-Upstreaming] Fix a crash (#52)
In case a function with skep attribute is instantiated two times with the same kernel name the attribute is invalid due to the conflicting name. Make sure to exit from instantiation of UnresolvedSYCLKernelCallStmt in this case.
1 parent dd8f6cf commit 1271ba3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12936,6 +12936,11 @@ ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
1293612936
template <typename Derived>
1293712937
StmtResult TreeTransform<Derived>::TransformUnresolvedSYCLKernelCallStmt(
1293812938
UnresolvedSYCLKernelCallStmt *S) {
12939+
auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
12940+
const auto *SKEPAttr = FD->getAttr<SYCLKernelEntryPointAttr>();
12941+
if (!SKEPAttr || SKEPAttr->isInvalidAttr())
12942+
return StmtError();
12943+
1293912944
ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
1294012945

1294112946
if (IdExpr.isInvalid())

clang/test/SemaSYCL/sycl-kernel-entry-point-attr-kernel-name.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,25 @@ struct B19 {
124124
};
125125
// expected-note@+1 {{in instantiation of template class 'B19<int>' requested here}}
126126
B19<int> b19;
127+
128+
struct auto_name;
129+
130+
// expected-error@+4 {{the 'clang::sycl_kernel_entry_point' kernel name argument conflicts with a previous declaration}}
131+
// expected-note@+3 {{previous declaration is here}}
132+
template <typename KernelName, typename KernelType>
133+
[[clang::sycl_kernel_entry_point(KernelName)]]
134+
void __kernel_single_task(const KernelType KernelFunc) {
135+
KernelFunc();
136+
}
137+
138+
template <typename KernelType, typename KernelName = auto_name>
139+
void pf(KernelType K) {
140+
// expected-note@+1 {{requested here}}
141+
__kernel_single_task<KernelName>(K);
142+
}
143+
144+
void foo() {
145+
pf([](){});
146+
// expected-note@+1 {{requested here}}
147+
pf([](){});
148+
}

0 commit comments

Comments
 (0)