Skip to content

Commit 455dce8

Browse files
authored
[SYCL] Improve error diagnostic for invalid SYCL kernel name (#4867)
According to SYCL 2020 spec: The kernel name must be forward declarable at namespace scope (including global namespace scope) and may not be forward declared other than at namespace scope. The use of nested struct-case (where the name IS globally visible but just not forward-declarable) in a SYCL kernel name currently generates invalid error message: error: '{{.*}}' should be globally visible This patch modifies the error diagnostic message when the kernel name is declared at non-namespace scope (i.e. Inside a function or class/struct). Signed-off-by: Soumi Manna soumi.manna@intel.com
1 parent 3623acb commit 455dce8

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11451,7 +11451,8 @@ def err_invalid_std_type_in_sycl_kernel : Error<"%0 is an invalid kernel name, "
1145111451
"%q1 is declared in the 'std' namespace ">;
1145211452

1145311453
def err_sycl_kernel_incorrectly_named : Error<
11454-
"%select{%1 should be globally visible"
11454+
"%select{%1 is invalid; kernel name should be forward declarable "
11455+
"at namespace scope"
1145511456
"|unscoped enum %1 requires fixed underlying type"
1145611457
"|unnamed type %1 is invalid; provide a kernel name, or use "
1145711458
"'-fsycl-unnamed-lambda' to enable unnamed kernel lambdas"

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,13 +3508,12 @@ class SYCLKernelNameTypeVisitor
35083508
}
35093509
// Check if the declaration is completely defined within a
35103510
// function or class/struct.
3511-
35123511
if (Tag->isCompleteDefinition()) {
35133512
S.Diag(KernelInvocationFuncLoc,
35143513
diag::err_sycl_kernel_incorrectly_named)
3515-
<< /* kernel name should be globally visible */ 0
3516-
<< KernelNameType;
3517-
3514+
<< /* kernel name should be forward declarable at namespace
3515+
scope */
3516+
0 << KernelNameType;
35183517
IsInvalid = true;
35193518
} else {
35203519
S.Diag(KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl);

clang/test/SemaSYCL/implicit_kernel_type.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@ class myWrapper2;
2222
int main() {
2323
queue q;
2424

25-
#if defined(WARN)
26-
// expected-error@#KernelSingleTask {{'InvalidKernelName1' should be globally visible}}
27-
// expected-note@+7 {{in instantiation of function template specialization}}
28-
#elif defined(ERROR)
29-
// expected-error@#KernelSingleTask {{'InvalidKernelName1' should be globally visible}}
30-
// expected-note@+4 {{in instantiation of function template specialization}}
31-
#endif
3225
class InvalidKernelName1 {};
26+
// expected-error@#KernelSingleTask {{'InvalidKernelName1' is invalid; kernel name should be forward declarable at namespace scope}}
27+
// expected-note@+2 {{in instantiation of function template specialization}}
3328
q.submit([&](handler &h) {
3429
h.single_task<InvalidKernelName1>([]() {});
3530
});

clang/test/SemaSYCL/nested-anon-and-std-ns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct MyWrapper {
3737
h.single_task<ValidNS::StructinValidNS>([] {});
3838
});
3939

40-
// expected-error@#KernelSingleTask {{'ParentStruct::ChildStruct' should be globally visible}}
40+
// expected-error@#KernelSingleTask {{'ParentStruct::ChildStruct' is invalid; kernel name should be forward declarable at namespace scope}}
4141
// expected-note@+2{{in instantiation of function template specialization}}
4242
q.submit([&](cl::sycl::handler &h) {
4343
h.single_task<ParentStruct::ChildStruct>([] {});

clang/test/SemaSYCL/unnamed-kernel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ struct MyWrapper {
3232
public:
3333
void test() {
3434
cl::sycl::queue q;
35-
// expected-error@#KernelSingleTask {{'InvalidKernelName1' should be globally visible}}
35+
// expected-error@#KernelSingleTask {{'InvalidKernelName1' is invalid; kernel name should be forward declarable at namespace scope}}
3636
// expected-note@+3{{in instantiation of function template specialization}}
3737
class InvalidKernelName1 {};
3838
q.submit([&](cl::sycl::handler &h) {
3939
h.single_task<InvalidKernelName1>([] {});
4040
});
4141

42-
// expected-error@#KernelSingleTask {{'namespace1::KernelName<InvalidKernelName2>' should be globally visible}}
42+
// expected-error@#KernelSingleTask {{'namespace1::KernelName<InvalidKernelName2>' is invalid; kernel name should be forward declarable at namespace scope}}
4343
// expected-note@+3{{in instantiation of function template specialization}}
4444
class InvalidKernelName2 {};
4545
q.submit([&](cl::sycl::handler &h) {
4646
h.single_task<namespace1::KernelName<InvalidKernelName2>>([] {});
4747
});
4848

49-
// expected-error@#KernelSingleTask {{'MyWrapper::InvalidKernelName0' should be globally visible}}
49+
// expected-error@#KernelSingleTask {{'MyWrapper::InvalidKernelName0' is invalid; kernel name should be forward declarable at namespace scope}}
5050
// expected-note@+2{{in instantiation of function template specialization}}
5151
q.submit([&](cl::sycl::handler &h) {
5252
h.single_task<InvalidKernelName0>([] {});
5353
});
5454

55-
// expected-error@#KernelSingleTask {{'namespace1::KernelName<MyWrapper::InvalidKernelName3>' should be globally visible}}
55+
// expected-error@#KernelSingleTask {{'namespace1::KernelName<MyWrapper::InvalidKernelName3>' is invalid; kernel name should be forward declarable at namespace scope}}
5656
// expected-note@+2{{in instantiation of function template specialization}}
5757
q.submit([&](cl::sycl::handler &h) {
5858
h.single_task<namespace1::KernelName<InvalidKernelName3>>([] {});
@@ -70,19 +70,19 @@ struct MyWrapper {
7070
});
7171

7272
using InvalidAlias = InvalidKernelName4;
73-
// expected-error@#KernelSingleTask {{'MyWrapper::InvalidKernelName4' should be globally visible}}
73+
// expected-error@#KernelSingleTask {{'MyWrapper::InvalidKernelName4' is invalid; kernel name should be forward declarable at namespace scope}}
7474
// expected-note@+2{{in instantiation of function template specialization}}
7575
q.submit([&](cl::sycl::handler &h) {
7676
h.single_task<InvalidAlias>([] {});
7777
});
7878

7979
using InvalidAlias1 = InvalidKernelName5;
80-
// expected-error@#KernelSingleTask {{'namespace1::KernelName<MyWrapper::InvalidKernelName5>' should be globally visible}}
80+
// expected-error@#KernelSingleTask {{'namespace1::KernelName<MyWrapper::InvalidKernelName5>' is invalid; kernel name should be forward declarable at namespace scope}}
8181
// expected-note@+2{{in instantiation of function template specialization}}
8282
q.submit([&](cl::sycl::handler &h) {
8383
h.single_task<namespace1::KernelName<InvalidAlias1>>([] {});
8484
});
85-
// expected-error@#KernelSingleTask {{'Templated_kernel_name2<Templated_kernel_name<InvalidKernelName1>>' should be globally visible}}
85+
// expected-error@#KernelSingleTask {{'Templated_kernel_name2<Templated_kernel_name<InvalidKernelName1>>' is invalid; kernel name should be forward declarable at namespace scope}}
8686
// expected-note@+2{{in instantiation of function template specialization}}
8787
q.submit([&](cl::sycl::handler &h) {
8888
h.single_task<Templated_kernel_name2<Templated_kernel_name<InvalidKernelName1>>>([] {});

0 commit comments

Comments
 (0)