Skip to content

Commit df1ff7a

Browse files
authored
[SYCL] Improve diagnostics for invalid kernel names (#4769)
The use of lambda (which is not forward-declarable) in a SYCL kernel name currently generates the error message: error: unnamed lambda ‘(lambda at {{.*}}filename.cpp{{.}’ used The diagnostic message is very confusing and doesn't help to understand what exactly is wrong. To update the message to make it better and more helpful, this patch modifies the error diagnostic when the lambdas (anonymous function object types) are used in SYCL kernel names. Signed-off-by: Soumi Manna <[email protected]>
1 parent 0e72f02 commit df1ff7a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11440,7 +11440,8 @@ def err_invalid_std_type_in_sycl_kernel : Error<"%0 is an invalid kernel name, "
1144011440
def err_sycl_kernel_incorrectly_named : Error<
1144111441
"%select{%1 should be globally visible"
1144211442
"|unscoped enum %1 requires fixed underlying type"
11443-
"|unnamed lambda %1 used"
11443+
"|unnamed type %1 is invalid; provide a kernel name, or use "
11444+
"'-fsycl-unnamed-lambda' to enable unnamed kernel lambdas"
1144411445
"}0">;
1144511446

1144611447
def err_sycl_kernel_not_function_object

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,8 +3502,7 @@ class SYCLKernelNameTypeVisitor
35023502
if (UnnamedLambdaUsed) {
35033503
S.Diag(KernelInvocationFuncLoc,
35043504
diag::err_sycl_kernel_incorrectly_named)
3505-
<< /* unnamed lambda used */ 2 << KernelNameType;
3506-
3505+
<< /* unnamed type is invalid */ 2 << KernelNameType;
35073506
IsInvalid = true;
35083507
return;
35093508
}

clang/test/SemaSYCL/unnamed-kernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct MyWrapper {
137137

138138
// This errors because const decltype(SomeLambda) != decltype(SomeLambda),
139139
// so this is not the unnamed lambda situation.
140-
// expected-error@#KernelSingleTask {{unnamed lambda 'const}}
140+
// expected-error@#KernelSingleTask {{unnamed type 'const}}
141141
// expected-note@+3{{in instantiation of function template specialization}}
142142
q.submit([&](cl::sycl::handler &h) {
143143
auto SomeLambda = []() {};
@@ -150,7 +150,7 @@ struct MyWrapper {
150150
int main() {
151151
cl::sycl::queue q;
152152
#ifndef __SYCL_UNNAMED_LAMBDA__
153-
// expected-error-re@#KernelSingleTask {{unnamed lambda '(lambda at {{.*}}unnamed-kernel.cpp{{.*}}' used}}
153+
// expected-error-re@#KernelSingleTask {{unnamed type '(lambda at {{.*}}unnamed-kernel.cpp{{.*}}' is invalid; provide a kernel name, or use '-fsycl-unnamed-lambda' to enable unnamed kernel lambdas}}
154154
// expected-note@+2{{in instantiation of function template specialization}}
155155
#endif
156156
q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); });

0 commit comments

Comments
 (0)