Skip to content

Commit 4afeea5

Browse files
[SYCL] Revert support for templated call operators in functors and functors without call operators (#8047)
This PR reverts the support for templated call operators in functors and functors without call operators which were introduced in #7104 and #7970 We found a regression internally with #7104 that #7970 attempted to fix. A subsequent review of #7970 internally, lead to identifying some pre-existing caveats with regards to supporting templated call operators in functor, supporting cases where there are multiple call operators in functor and making sure the right instantiated version is selected etc. In order to better address the pre-existing issues as well as gaps in #7970 , it was decided to revert the above two PRs.
1 parent ab69ac8 commit 4afeea5

File tree

2 files changed

+18
-93
lines changed

2 files changed

+18
-93
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -991,42 +991,6 @@ static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
991991
return KernelParamTy.getUnqualifiedType();
992992
}
993993

994-
// Get the call operator function associated with the function object
995-
// for both templated and non-templated operator()().
996-
997-
static CXXMethodDecl *getFunctorCallOperator(const CXXRecordDecl *RD) {
998-
DeclarationName Name =
999-
RD->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
1000-
DeclContext::lookup_result Calls = RD->lookup(Name);
1001-
1002-
if (Calls.empty())
1003-
return nullptr;
1004-
1005-
NamedDecl *CallOp = Calls.front();
1006-
1007-
if (CallOp == nullptr)
1008-
return nullptr;
1009-
1010-
if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
1011-
return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
1012-
1013-
return cast<CXXMethodDecl>(CallOp);
1014-
}
1015-
1016-
// Fetch the associated call operator of the kernel object
1017-
// (of either the lambda or the function object).
1018-
static CXXMethodDecl *
1019-
GetCallOperatorOfKernelObject(const CXXRecordDecl *KernelObjType) {
1020-
CXXMethodDecl *CallOperator = nullptr;
1021-
if (!KernelObjType)
1022-
return CallOperator;
1023-
if (KernelObjType->isLambda())
1024-
CallOperator = KernelObjType->getLambdaCallOperator();
1025-
else
1026-
CallOperator = getFunctorCallOperator(KernelObjType);
1027-
return CallOperator;
1028-
}
1029-
1030994
/// Creates a kernel parameter descriptor
1031995
/// \param Src field declaration to construct name from
1032996
/// \param Ty the desired parameter type
@@ -2815,8 +2779,16 @@ class SyclOptReportCreator : public SyclKernelFieldHandler {
28152779
}
28162780
};
28172781

2782+
static CXXMethodDecl *getOperatorParens(const CXXRecordDecl *Rec) {
2783+
for (auto *MD : Rec->methods()) {
2784+
if (MD->getOverloadedOperator() == OO_Call)
2785+
return MD;
2786+
}
2787+
return nullptr;
2788+
}
2789+
28182790
static bool isESIMDKernelType(const CXXRecordDecl *KernelObjType) {
2819-
const CXXMethodDecl *OpParens = getFunctorCallOperator(KernelObjType);
2791+
const CXXMethodDecl *OpParens = getOperatorParens(KernelObjType);
28202792
return (OpParens != nullptr) && OpParens->hasAttr<SYCLSimdAttr>();
28212793
}
28222794

@@ -2903,10 +2875,13 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
29032875

29042876
// Fetch the kernel object and the associated call operator
29052877
// (of either the lambda or the function object).
2906-
const CXXRecordDecl *KernelObj =
2878+
CXXRecordDecl *KernelObj =
29072879
GetSYCLKernelObjectType(KernelCallerFunc)->getAsCXXRecordDecl();
2908-
CXXMethodDecl *WGLambdaFn = GetCallOperatorOfKernelObject(KernelObj);
2909-
2880+
CXXMethodDecl *WGLambdaFn = nullptr;
2881+
if (KernelObj->isLambda())
2882+
WGLambdaFn = KernelObj->getLambdaCallOperator();
2883+
else
2884+
WGLambdaFn = getOperatorParens(KernelObj);
29102885
assert(WGLambdaFn && "non callable object is passed as kernel obj");
29112886
// Mark the function that it "works" in a work group scope:
29122887
// NOTE: In case of parallel_for_work_item the marker call itself is
@@ -3563,7 +3538,7 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
35633538
static bool IsSYCLUnnamedKernel(Sema &SemaRef, const FunctionDecl *FD) {
35643539
if (!SemaRef.getLangOpts().SYCLUnnamedLambda)
35653540
return false;
3566-
const QualType FunctorTy = GetSYCLKernelObjectType(FD);
3541+
QualType FunctorTy = GetSYCLKernelObjectType(FD);
35673542
QualType TmplArgTy = calculateKernelNameType(SemaRef.Context, FD);
35683543
return SemaRef.Context.hasSameType(FunctorTy, TmplArgTy);
35693544
}
@@ -3989,7 +3964,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
39893964
const CXXRecordDecl *KernelObj =
39903965
GetSYCLKernelObjectType(KernelFunc)->getAsCXXRecordDecl();
39913966

3992-
if (!GetCallOperatorOfKernelObject(KernelObj)) {
3967+
if (!KernelObj) {
39933968
Diag(Args[0]->getExprLoc(), diag::err_sycl_kernel_not_function_object);
39943969
KernelFunc->setInvalidDecl();
39953970
return;
@@ -4055,7 +4030,7 @@ void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc,
40554030
// kernel to wrapped kernel.
40564031
void Sema::copySYCLKernelAttrs(const CXXRecordDecl *KernelObj) {
40574032
// Get the operator() function of the wrapper.
4058-
CXXMethodDecl *OpParens = getFunctorCallOperator(KernelObj);
4033+
CXXMethodDecl *OpParens = getOperatorParens(KernelObj);
40594034
assert(OpParens && "invalid kernel object");
40604035

40614036
typedef std::pair<FunctionDecl *, FunctionDecl *> ChildParentPair;

clang/test/SemaSYCL/undefined-functor.cpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)