Skip to content

Commit 41f0b59

Browse files
authored
Revert "[SYCL] Move function pointer diagnostics to BuildResolvedCallExpr (#1…"
This reverts commit 270bb93.
1 parent b1d9368 commit 41f0b59

File tree

3 files changed

+11
-32
lines changed

3 files changed

+11
-32
lines changed

clang/lib/Sema/SemaExpr.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -7124,18 +7124,6 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
71247124
return ExprError();
71257125
}
71267126

7127-
// Diagnose function pointers in SYCL.
7128-
if (!FDecl && !getLangOpts().SYCLAllowFuncPtr && getLangOpts().SYCLIsDevice &&
7129-
!isUnevaluatedContext()) {
7130-
bool MaybeConstantExpr = false;
7131-
Expr *NonDirectCallee = TheCall->getCallee();
7132-
if (!NonDirectCallee->isValueDependent())
7133-
MaybeConstantExpr = NonDirectCallee->isCXX11ConstantExpr(getASTContext());
7134-
if (!MaybeConstantExpr)
7135-
SYCL().DiagIfDeviceCode(TheCall->getExprLoc(), diag::err_sycl_restrict)
7136-
<< SemaSYCL::KernelCallFunctionPointer;
7137-
}
7138-
71397127
return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), FDecl);
71407128
}
71417129

clang/lib/Sema/SemaSYCL.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,17 @@ class DiagDeviceFunction : public RecursiveASTVisitor<DiagDeviceFunction> {
693693
SemaSYCLRef.Diag(e->getExprLoc(), diag::err_builtin_target_unsupported)
694694
<< Name << "SYCL device";
695695
}
696+
} else if (!SemaSYCLRef.getLangOpts().SYCLAllowFuncPtr &&
697+
!e->isTypeDependent() &&
698+
!isa<CXXPseudoDestructorExpr>(e->getCallee())) {
699+
bool MaybeConstantExpr = false;
700+
Expr *NonDirectCallee = e->getCallee();
701+
if (!NonDirectCallee->isValueDependent())
702+
MaybeConstantExpr =
703+
NonDirectCallee->isCXX11ConstantExpr(SemaSYCLRef.getASTContext());
704+
if (!MaybeConstantExpr)
705+
SemaSYCLRef.Diag(e->getExprLoc(), diag::err_sycl_restrict)
706+
<< SemaSYCL::KernelCallFunctionPointer;
696707
}
697708
return true;
698709
}

clang/test/SemaSYCL/constexpr-function-pointer.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -sycl-std=2020 -std=c++17 %s
2-
// RUN: %clang_cc1 -fsycl-is-host -fsyntax-only -verify=host -sycl-std=2020 -std=c++17 %s
32

43
// This test checks that the compiler doesn't emit an error when indirect call
54
// was made through a function pointer that is constant expression, and makes
65
// sure that the error is emitted when a function pointer is not a constant
76
// expression.
87

9-
// host-no-diagnostics
10-
118
void t() {}
129

1310
constexpr auto F = t;
@@ -25,8 +22,6 @@ void bar1(const SomeFunc fptr) {
2522

2623
template <auto f> void fooNTTP() { f(); }
2724

28-
template <typename FTy> void templated(FTy f) { f(); } // #call-templated
29-
3025
__attribute__((sycl_device)) void bar() {
3126
// OK
3227
constexpr auto f = t;
@@ -53,19 +48,4 @@ __attribute__((sycl_device)) void bar() {
5348
fff();
5449

5550
fooNTTP<t>();
56-
57-
templated(t);
58-
// expected-error@#call-templated {{SYCL kernel cannot call through a function pointer}}
59-
// expected-note@-2 {{called by 'bar'}}
60-
}
61-
62-
void from_host() {
63-
const auto f1 = t;
64-
f1();
65-
auto f2 = t;
66-
f2();
67-
68-
fooNTTP<t>();
69-
70-
templated(t);
7151
}

0 commit comments

Comments
 (0)