diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 682d2ebf97689..15d86255c5bdc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4458,6 +4458,12 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, if (FD) diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc); + + // Diagnose variadic calls in SYCL. + if (FD && FD ->isVariadic() && getLangOpts().SYCLIsDevice && + !isUnevaluatedContext() && !isKnownGoodSYCLDecl(FD)) + SYCLDiagIfDeviceCode(Loc, diag::err_sycl_restrict) + << Sema::KernelCallVariadicFunction; } /// CheckConstructorCall - Check a constructor call for correctness and safety diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index be815cc22a5f6..ac2a9e1cff08e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5404,12 +5404,6 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, // Otherwise do argument promotion, (C99 6.5.2.2p7). } else { - // Diagnose variadic calls in SYCL. - if (getLangOpts().SYCLIsDevice && !isUnevaluatedContext() && - !isKnownGoodSYCLDecl(FDecl)) - SYCLDiagIfDeviceCode(CallLoc, diag::err_sycl_restrict) - << Sema::KernelCallVariadicFunction; - for (Expr *A : Args.slice(ArgIx)) { ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl); Invalid |= Arg.isInvalid(); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 4e2e3bbf4f173..5fb59b545176d 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -14230,11 +14230,6 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj, // If this is a variadic call, handle args passed through "...". if (Proto->isVariadic()) { - // Diagnose variadic calls in SYCL. - if (getLangOpts().SYCLIsDevice && !isUnevaluatedContext()) - SYCLDiagIfDeviceCode(LParenLoc, diag::err_sycl_restrict) - << Sema::KernelCallVariadicFunction; - // Promote the arguments (C99 6.5.2.2p7). for (unsigned i = NumParams, e = Args.size(); i < e; i++) { ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod, diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 477ec98b4d48f..25a6b6b02cc19 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -1391,10 +1391,6 @@ static bool isKnownEmitted(Sema &S, FunctionDecl *FD) { if (!FD) return true; // Seen in LIT testing - // Templates are emitted when they're instantiated. - if (FD->isDependentContext()) - return false; - if (FD->hasAttr() || FD->hasAttr()) return true; @@ -1409,7 +1405,7 @@ Sema::DeviceDiagBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc, "Should only be called during SYCL compilation"); FunctionDecl *FD = dyn_cast(getCurLexicalContext()); DeviceDiagBuilder::Kind DiagKind = [this, FD] { - if (ConstructingOpenCLKernel || (FD && FD->isDependentContext())) + if (ConstructingOpenCLKernel) return DeviceDiagBuilder::K_Nop; else if (isKnownEmitted(*this, FD)) return DeviceDiagBuilder::K_ImmediateWithCallStack; diff --git a/clang/test/SemaSYCL/inline-asm.cpp b/clang/test/SemaSYCL/inline-asm.cpp index 6290c01367bfb..4d414e29a9aa7 100644 --- a/clang/test/SemaSYCL/inline-asm.cpp +++ b/clang/test/SemaSYCL/inline-asm.cpp @@ -23,6 +23,11 @@ template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { // expected-note@+1 {{called by 'kernel_single_task +__attribute__((sycl_kernel)) +void kernel_single_task(Func kernelFunc) { + // expected-note@+1 {{called by 'kernel_single_task}} + kernelFunc(); +} + +void foo() { + // expected-error@+1 {{SYCL kernel cannot use exceptions}} + throw 3; +} + +int main() { +// expected-note@+1 {{called by 'operator()'}} +kernel_single_task([]() { foo(); }); +} diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index 89dd0adeffe01..083b7f775f2cc 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -124,7 +124,6 @@ void eh_not_ok(void) void usage(myFuncDef functionPtr) { - // expected-note@+1 {{called by 'usage'}} eh_not_ok(); #if ALLOW_FP @@ -170,6 +169,7 @@ int use2 ( a_type ab, a_type *abp ) { return ns::glob + // expected-error@+1 {{SYCL kernel cannot use a global variable}} AnotherNS::moar_globals; + // expected-note@+1 {{called by 'use2'}} eh_not_ok(); Check_RTTI_Restriction:: A *a; Check_RTTI_Restriction:: isa_B(a); @@ -180,16 +180,15 @@ int use2 ( a_type ab, a_type *abp ) { template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { - // expected-note@+1 {{called by 'kernel_single_task}} kernelFunc(); a_type ab; a_type *p; + // expected-note@+1 {{called by 'kernel_single_task'}} use2(ab, p); } int main() { a_type ab; - // expected-note@+1 {{called by 'operator()'}} kernel_single_task([]() { usage( &addInt ); }); return 0; }