Skip to content

Commit 49ebe5e

Browse files
[SYCL] Fix SYCL Kernel Body Check (#5546)
SYCLKernelAttr can be used to check if a given function is a SYCL kernel body function or not. A SYCL kernel body function is the operator() method of a SYCL Kernel Functor or Lambda Function. The existing check which only tested if a FunctionDecl was an operator or not, allowed for false positives. This patch adds an additional check for SYCLKernelAttr, which will be attached to the kernel body function's parent/ parent's parent (for wrapped kernels) Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent 73d59ce commit 49ebe5e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ class SingleDeviceFunctionTracker {
823823
// false-positives.
824824
if (isSYCLKernelBodyFunction(CurrentDecl)) {
825825
// This is a direct callee of the kernel.
826-
if (CallStack.size() == 1) {
826+
if (CallStack.size() == 1 &&
827+
CallStack.back()->hasAttr<SYCLKernelAttr>()) {
827828
assert(!KernelBody && "inconsistent call graph - only one kernel body "
828829
"function can be called");
829830
KernelBody = CurrentDecl;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -verify %s
2+
3+
// Test to verify that non-kernel functors are not processed as SYCL kernel
4+
// functors
5+
6+
// expected-no-diagnostics
7+
class First {
8+
public:
9+
void operator()() { return; }
10+
};
11+
12+
class Second {
13+
public:
14+
First operator()() { return First(); }
15+
};
16+
17+
SYCL_EXTERNAL
18+
void foo() {
19+
Second NonKernelFunctorObj;
20+
NonKernelFunctorObj()();
21+
}

0 commit comments

Comments
 (0)