Skip to content

Commit ab9dd08

Browse files
committed
Apply code review comments
Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent f9f765d commit ab9dd08

File tree

10 files changed

+86
-19
lines changed

10 files changed

+86
-19
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10316,6 +10316,8 @@ def note_sycl_used_here : Note<"used here">;
1031610316
def note_sycl_recursive_function_declared_here: Note<"function implemented using recursion declared here">;
1031710317
def err_sycl_non_trivially_copyable_type : Error<
1031810318
"kernel parameter has non-trivially copyable class/struct type %0">;
10319+
def err_sycl_non_std_layout_type : Error<
10320+
"kernel parameter has non-standard layout class/struct type %0">;
1031910321
def err_conflicting_sycl_kernel_attributes : Error<
1032010322
"conflicting attributes applied to a SYCL kernel">;
1032110323
def err_conflicting_sycl_function_attributes : Error<

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kerne
233233
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
234234
LANGOPT(SYCLIsHost , 1, 0, "SYCL host compilation")
235235
LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
236+
LANGOPT(SYCLNewKernelParamReq, 1, 0, "Enable trivially copyable requirement instead of standard layout requirement for SYCL kernel parameters.")
236237
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
237238

238239
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")

clang/include/clang/Driver/CC1Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ def fsycl_int_header : Separate<["-"], "fsycl-int-header">,
899899
HelpText<"Generate SYCL integration header into this file.">;
900900
def fsycl_int_header_EQ : Joined<["-"], "fsycl-int-header=">,
901901
Alias<fsycl_int_header>;
902+
def fsycl_new_kernel_param_requirements: Flag<["-"], "fsycl-new-kernel-param-requirements">,
903+
HelpText<"Enable trivially copyable requirement instead of standard layout requirement for SYCL kernel parameters.">;
902904
def fsycl_allow_func_ptr : Flag<["-"], "fsycl-allow-func-ptr">,
903905
HelpText<"Allow function pointers in SYCL device.">;
904906
def fno_sycl_allow_func_ptr : Flag<["-"], "fno-sycl-allow-func-ptr">;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,6 +3992,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
39923992
} else if (IsSYCL) {
39933993
// Ensure the default version in SYCL mode is 1.2.1
39943994
CmdArgs.push_back("-sycl-std=1.2.1");
3995+
CmdArgs.push_back("-fsycl-new-kernel-param-requirements");
39953996
}
39963997

39973998
if (IsOpenMPDevice) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
31303130
Opts.SYCLIsHost = Args.hasArg(options::OPT_fsycl_is_host);
31313131
Opts.SYCLAllowFuncPtr = Args.hasFlag(options::OPT_fsycl_allow_func_ptr,
31323132
options::OPT_fno_sycl_allow_func_ptr, false);
3133+
Opts.SYCLNewKernelParamReq =
3134+
Args.hasArg(options::OPT_fsycl_new_kernel_param_requirements);
31333135
Opts.SYCLUnnamedLambda = Args.hasArg(options::OPT_fsycl_unnamed_lambda);
31343136

31353137
// Set CUDA mode for OpenMP target NVPTX if specified in options

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,15 +1033,25 @@ static bool buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj,
10331033
if (Util::isSyclAccessorType(ArgTy) || Util::isSyclSamplerType(ArgTy)) {
10341034
createSpecialSYCLObjParamDesc(Fld, ArgTy);
10351035
} else if (ArgTy->isStructureOrClassType()) {
1036-
// TODO: Make stream class trivially copyable and remove the check on
1037-
// stream class.
1038-
if (!ArgTy.isTriviallyCopyableType(Context) &&
1039-
!Util::isSyclStreamType(ArgTy)) {
1040-
Context.getDiagnostics().Report(
1041-
Fld->getLocation(), diag::err_sycl_non_trivially_copyable_type)
1042-
<< ArgTy;
1043-
AllArgsAreValid = false;
1044-
continue;
1036+
if (Context.getLangOpts().SYCLNewKernelParamReq) {
1037+
// TODO: Make stream class trivially copyable and remove the check on
1038+
// stream class.
1039+
if (!ArgTy.isTriviallyCopyableType(Context) &&
1040+
!Util::isSyclStreamType(ArgTy)) {
1041+
Context.getDiagnostics().Report(
1042+
Fld->getLocation(), diag::err_sycl_non_trivially_copyable_type)
1043+
<< ArgTy;
1044+
AllArgsAreValid = false;
1045+
continue;
1046+
}
1047+
} else {
1048+
if (!ArgTy->isStandardLayoutType()) {
1049+
Context.getDiagnostics().Report(Fld->getLocation(),
1050+
diag::err_sycl_non_std_layout_type)
1051+
<< ArgTy;
1052+
AllArgsAreValid = false;
1053+
continue;
1054+
}
10451055
}
10461056

10471057
CreateAndAddPrmDsc(Fld, ArgTy);

clang/test/CodeGenSYCL/non-standard-layout.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-linux-sycldevice -aux-triple x86_64-unknown-windows-unknown -std=c++11 -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-WIN %s
2-
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-linux-sycldevice -aux-triple x86_64-unknown-linux-unknown -std=c++11 -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-LIN %s
1+
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-windows-unknown -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-WIN %s
2+
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-linux-unknown -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-LIN %s
33

44
#include "sycl.hpp"
55
// CHK-WIN: %struct{{.*}}F = type { i8, i8 }
@@ -10,14 +10,10 @@ struct F : F1, F2 {
1010
char x;
1111
};
1212

13-
template <typename name, typename Func>
14-
__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
15-
kernelFunc();
16-
}
17-
1813
int main() {
1914
cl::sycl::accessor<F, 1, cl::sycl::access::mode::read_write> accessorA;
20-
kernel<class kernel_function>(
15+
cl::sycl::handler cgh;
16+
cgh.single_task<class kernel_function>(
2117
[=]() {
2218
accessorA.use();
2319
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s
2+
3+
// This test checks if compiler reports compilation error on an attempt to pass
4+
// non-standard layout struct object as SYCL kernel parameter.
5+
6+
struct Base {
7+
int X;
8+
};
9+
10+
// This struct has non-standard layout, because both C (the most derived class)
11+
// and Base have non-static data members.
12+
struct C : public Base {
13+
int Y;
14+
};
15+
16+
template <typename name, typename Func>
17+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
18+
kernelFunc();
19+
}
20+
21+
22+
void test() {
23+
C C0;
24+
C0.Y=0;
25+
kernel_single_task<class MyKernel>([=] {
26+
// expected-error@+1 {{kernel parameter has non-standard layout class/struct type 'C'}}
27+
(void)C0.Y;
28+
});
29+
}
30+
31+
struct Kernel {
32+
void operator()() {
33+
(void) c1;
34+
(void) c2;
35+
(void) p;
36+
(void) q;
37+
}
38+
39+
int p;
40+
// expected-error@+1 {{kernel parameter has non-standard layout class/struct type 'C'}}
41+
C c1;
42+
43+
int q;
44+
45+
// expected-error@+1 {{kernel parameter has non-standard layout class/struct type 'C'}}
46+
C c2;
47+
};
48+
49+
void test_struct_field() {
50+
Kernel k{};
51+
52+
kernel_single_task<class kernel_object>(k);
53+
}

clang/test/SemaSYCL/non-trivially-copyable-kernel-param.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -std=c++11 %s
1+
// RUN: %clang_cc1 -fsycl-is-device -fsycl-new-kernel-param-requirements -verify -fsyntax-only %s
22

33
// This test checks if compiler reports compilation error on an attempt to pass
44
// a struct with non-trivially copyable type as SYCL kernel parameter.

clang/test/SemaSYCL/reference-kernel-param.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only -std=c++11 %s
1+
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s
22

33
// This test checks if compiler reports compilation error on an attempt to pass
44
// a reference as SYCL kernel parameter.

0 commit comments

Comments
 (0)