Skip to content

Commit 0b88367

Browse files
committed
Improve diagnotic messages
1 parent 431a405 commit 0b88367

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12414,6 +12414,14 @@ def err_sycl_kernel_incorrectly_named : Error<
1241412414
"'-fsycl-unnamed-lambda' to enable unnamed kernel lambdas"
1241512415
"}0">;
1241612416

12417+
// SYCL free function kernels extension.
12418+
def err_bad_free_function_kernel_param_type : Error<
12419+
"%0 cannot be used as the type of a free function kernel parameter">;
12420+
def note_free_function_kernel_param_type_not_fwd_declarable : Note<
12421+
"%0 is not forward declarable">;
12422+
def note_free_function_kernel_param_type_not_supported : Note<
12423+
"%0 is not yet supported as free function kernel parameter">;
12424+
1241712425
def err_sycl_kernel_not_function_object
1241812426
: Error<"kernel parameter must be a lambda or function object">;
1241912427
def err_sycl_restrict : Error<

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,11 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
19661966
// arguments.
19671967
// Lambdas are not forward declarable. So, diagnose them properly.
19681968
if (RD->isLambda()) {
1969-
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
1969+
Diag.Report(PD->getLocation(),
1970+
diag::err_bad_free_function_kernel_param_type)
1971+
<< ParamTy;
1972+
Diag.Report(PD->getLocation(),
1973+
diag::note_free_function_kernel_param_type_not_fwd_declarable)
19701974
<< ParamTy;
19711975
IsInvalid = true;
19721976
return isValid();
@@ -1979,7 +1983,11 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
19791983
DeclCtx = DeclCtx->getParent();
19801984

19811985
if (!DeclCtx->isTranslationUnit()) {
1982-
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
1986+
Diag.Report(PD->getLocation(),
1987+
diag::err_bad_free_function_kernel_param_type)
1988+
<< ParamTy;
1989+
Diag.Report(PD->getLocation(),
1990+
diag::note_free_function_kernel_param_type_not_fwd_declarable)
19831991
<< ParamTy;
19841992
IsInvalid = true;
19851993
}
@@ -2077,7 +2085,11 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
20772085
// experience.
20782086
CXXRecordDecl *RD = ParamTy->getAsCXXRecordDecl();
20792087
if (RD->hasAttr<SYCLRequiresDecompositionAttr>()) {
2080-
Diag.Report(PD->getLocation(), diag::err_bad_kernel_param_type)
2088+
Diag.Report(PD->getLocation(),
2089+
diag::err_bad_free_function_kernel_param_type)
2090+
<< ParamTy;
2091+
Diag.Report(PD->getLocation(),
2092+
diag::note_free_function_kernel_param_type_not_supported)
20812093
<< ParamTy;
20822094
IsInvalid = true;
20832095
}

clang/test/SemaSYCL/free_function_kernel_params_restrictions.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ class Outer {
1313

1414
__attribute__((sycl_device))
1515
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
16-
void ff_4(Outer::DefinedWithinAClass S1) { // expected-error {{'Outer::DefinedWithinAClass' cannot be used as the type of a kernel parameter}}
16+
void ff_4(Outer::DefinedWithinAClass S1) { // expected-error {{'Outer::DefinedWithinAClass' cannot be used as the type of a free function kernel parameter}}
17+
// expected-note@-1 {{'Outer::DefinedWithinAClass' is not forward declarable}}
1718
}
1819

1920
template <typename T1>
2021
__attribute__((sycl_device))
2122
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
22-
void ff_6(T1 S1) { // expected-error 2{{cannot be used as the type of a kernel parameter}}
23+
void ff_6(T1 S1) { // expected-error 2{{cannot be used as the type of a free function kernel parameter}}
24+
// expected-note@-1 2{{is not forward declarable}}
2325
}
2426

2527
void bar() {
@@ -54,5 +56,6 @@ struct Wrapper {
5456
};
5557

5658
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 0)]]
57-
void ff_6(Wrapper S1) { // expected-error {{cannot be used as the type of a kernel parameter}}
59+
void ff_6(Wrapper S1) { // expected-error {{cannot be used as the type of a free function kernel parameter}}
60+
// expected-note@-1 {{'Wrapper' is not yet supported as free function kernel parameter}}
5861
}

0 commit comments

Comments
 (0)