Skip to content

Commit 59baed4

Browse files
Fznamznontahonermann
authored andcommitted
[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 c1ffcf8 commit 59baed4

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
@@ -12969,6 +12969,11 @@ ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
1296912969
template <typename Derived>
1297012970
StmtResult TreeTransform<Derived>::TransformUnresolvedSYCLKernelCallStmt(
1297112971
UnresolvedSYCLKernelCallStmt *S) {
12972+
auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
12973+
const auto *SKEPAttr = FD->getAttr<SYCLKernelEntryPointAttr>();
12974+
if (!SKEPAttr || SKEPAttr->isInvalidAttr())
12975+
return StmtError();
12976+
1297212977
ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
1297312978

1297412979
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)