Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
18 changes: 15 additions & 3 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,22 @@ static bool buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj,
continue;
}
}
if (!ArgTy.isTriviallyCopyableType(Context)) {

CXXRecordDecl *RD =
cast<CXXRecordDecl>(ArgTy->getAs<RecordType>()->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;
}
Expand Down
17 changes: 16 additions & 1 deletion clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
Expand All @@ -20,9 +30,14 @@ void test() {
A IamGood;
IamGood.i = 0;
B IamBad(1);
C IamAlsoGood;
D IamAlsoBad{0};
kernel_single_task<class kernel_capture_refs>([=] {
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;
});
}