Skip to content

Commit 3c9006e

Browse files
premanandraobader
authored andcommitted
[SYCL] Do not issue an error for pseudo-destructor expr (#855)
A pseudo-destructor expression may appear within sycl_kernel functions. Do not diagnose this as a function-ptr call. Signed-off-by: Premanand M Rao <[email protected]>
1 parent 4ba499c commit 3c9006e

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
244244
diag::err_builtin_target_unsupported)
245245
<< Name << "SYCL device";
246246
}
247-
} else if ((!SemaRef.getLangOpts().SYCLAllowFuncPtr) &&
248-
!e->isTypeDependent())
247+
} else if (!SemaRef.getLangOpts().SYCLAllowFuncPtr &&
248+
!e->isTypeDependent() &&
249+
!isa<CXXPseudoDestructorExpr>(e->getCallee()))
249250
SemaRef.Diag(e->getExprLoc(), diag::err_sycl_restrict)
250251
<< Sema::KernelCallFunctionPointer;
251252
return true;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -x c++ %s
2+
3+
template <typename functor_t>
4+
struct functor_wrapper{
5+
functor_t f;
6+
7+
auto operator()() -> void {
8+
return;
9+
};
10+
};
11+
12+
// expected-error@+1 2{{SYCL kernel cannot have a class with a virtual function table}}
13+
struct S { virtual void foo(); };
14+
// expected-error@+1 2{{SYCL kernel cannot have a class with a virtual function table}}
15+
struct T { virtual ~T(); };
16+
17+
template <typename name, typename Func>
18+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
19+
// expected-no-note@+1
20+
using DATA_I = int;
21+
// expected-note@+1{{used here}}
22+
using DATA_S = S;
23+
// expected-note@+1{{used here}}
24+
using DATA_T = T;
25+
// this expression should be okay
26+
auto functor = [](DATA_I & v1, DATA_S &v2, DATA_T& v3) {
27+
// expected-no-error@+1
28+
v1.~DATA_I();
29+
// expected-note@+1{{used here}}
30+
v2.~DATA_S();
31+
// expected-error@+2{{SYCL kernel cannot call a virtual function}}
32+
// expected-note@+1{{used here}}
33+
v3.~DATA_T();
34+
};
35+
auto wrapped_functor = functor_wrapper<decltype(functor)>{functor};
36+
wrapped_functor();
37+
}
38+
39+
int main() {
40+
kernel_single_task<class fake_kernel>([]() { });
41+
return 0;
42+
}

0 commit comments

Comments
 (0)