diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 02cad98277ddc..308e5f3a457ef 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10490,8 +10490,9 @@ def err_sycl_virtual_types : Error< "No class with a vtable can be used in a SYCL kernel or any code included in the kernel">; def note_sycl_used_here : Note<"used here">; def note_sycl_recursive_function_declared_here: Note<"function implemented using recursion declared here">; -def err_sycl_non_trivially_copyable_type : Error< - "kernel parameter has non-trivially copyable class/struct type %0">; +def err_sycl_non_trivially_copy_ctor_dtor_type + : Error<"kernel parameter has non-trivially %select{copy " + "constructible|destructible}0 class/struct type %1">; def err_sycl_non_std_layout_type : Error< "kernel parameter has non-standard layout class/struct type %0">; def err_conflicting_sycl_kernel_attributes : Error< diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index dee3ede03370b..af257347d8823 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -1069,10 +1069,22 @@ static bool buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj, continue; } } - if (!ArgTy.isTriviallyCopyableType(Context)) { + + CXXRecordDecl *RD = + cast(ArgTy->getAs()->getDecl()); + if (!RD->hasTrivialCopyConstructor()) { + Context.getDiagnostics().Report( + Fld->getLocation(), + diag::err_sycl_non_trivially_copy_ctor_dtor_type) + << 0 << ArgTy; + AllArgsAreValid = false; + continue; + } + if (!RD->hasTrivialDestructor()) { Context.getDiagnostics().Report( - Fld->getLocation(), diag::err_sycl_non_trivially_copyable_type) - << ArgTy; + Fld->getLocation(), + diag::err_sycl_non_trivially_copy_ctor_dtor_type) + << 1 << ArgTy; AllArgsAreValid = false; continue; } diff --git a/clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp b/clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp index 70f4ba9f66808..58cfe0c1eba4a 100644 --- a/clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp +++ b/clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp @@ -11,6 +11,16 @@ struct B { B (const B& x) : i(x.i) {} }; +struct C : A { + const A C2; + C() : A{0}, C2{2}{} +}; + +struct D { + int i; + ~D(); +}; + template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { kernelFunc(); @@ -20,9 +30,14 @@ void test() { A IamGood; IamGood.i = 0; B IamBad(1); + C IamAlsoGood; + D IamAlsoBad{0}; kernel_single_task([=] { int a = IamGood.i; - // expected-error@+1 {{kernel parameter has non-trivially copyable class/struct type}} + // expected-error@+1 {{kernel parameter has non-trivially copy constructible class/struct type}} int b = IamBad.i; + int c = IamAlsoGood.i; + // expected-error@+1 {{kernel parameter has non-trivially destructible class/struct type}} + int d = IamAlsoBad.i; }); }