Skip to content

Commit b2bf167

Browse files
[SYCL] Fix crash caused by functor without call operator passed as Kernel.
1 parent 2cefad1 commit b2bf167

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,11 @@ static bool isESIMDKernelType(const CXXRecordDecl *KernelObjType) {
24122412
return (OpParens != nullptr) && OpParens->hasAttr<SYCLSimdAttr>();
24132413
}
24142414

2415+
static bool isSYCLKernelDefinedAsAFunctor(const CXXRecordDecl *KernelObjType) {
2416+
const CXXMethodDecl *OpParens = getOperatorParens(KernelObjType);
2417+
return (OpParens != nullptr);
2418+
}
2419+
24152420
class SyclKernelBodyCreator : public SyclKernelFieldHandler {
24162421
SyclKernelDeclCreator &DeclCreator;
24172422
llvm::SmallVector<Stmt *, 16> BodyStmts;
@@ -3457,7 +3462,8 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc,
34573462
const CXXRecordDecl *KernelObj =
34583463
GetSYCLKernelObjectType(KernelFunc)->getAsCXXRecordDecl();
34593464

3460-
if (!KernelObj) {
3465+
bool IsKernelAValidFunctor = isSYCLKernelDefinedAsAFunctor(KernelObj);
3466+
if (!KernelObj || !IsKernelAValidFunctor) {
34613467
Diag(Args[0]->getExprLoc(), diag::err_sycl_kernel_not_function_object);
34623468
KernelFunc->setInvalidDecl();
34633469
return;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -verify -fsyntax-only %s
2+
3+
#include "sycl.hpp"
4+
5+
using namespace sycl;
6+
queue q;
7+
8+
struct FunctorWithoutCallOperator; // expected-note {{forward declaration of 'FunctorWithoutCallOperator'}}
9+
10+
int main() {
11+
// expected-error@#KernelSingleTask {{kernel parameter must be a lambda or function object}}
12+
q.submit([&](sycl::handler &cgh) {
13+
// expected-error@+2 {{invalid use of incomplete type 'FunctorWithoutCallOperator'}}
14+
// expected-note@+1 {{in instantiation of function template specialization}}
15+
cgh.single_task(FunctorWithoutCallOperator{});
16+
});
17+
18+
}

0 commit comments

Comments
 (0)