Skip to content

Commit 4595b15

Browse files
Address review comments
1 parent ea65d90 commit 4595b15

File tree

6 files changed

+68
-30
lines changed

6 files changed

+68
-30
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11150,7 +11150,7 @@ def err_ext_int_max_size : Error<"%select{signed|unsigned}0 _ExtInt of bit "
1115011150
def err_esimd_glob_cant_init : Error<
1115111151
"SYCL explicit SIMD does not permit private global variable to have an initializer">;
1115211152

11153-
def err_invalid_std_type_in_sycl_kernel : Error<"%0 is an invalid kernel name,type %1 cannot be in the \'std\' namespace ">;
11153+
def err_invalid_std_type_in_sycl_kernel : Error<"%0 is an invalid kernel name, %q1 is declared in the \'std\' namespace ">;
1115411154

1115511155
def err_sycl_kernel_incorrectly_named : Error<
1115611156
"%select{%1 should be globally-visible"

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@ class SYCLKernelNameTypeVisitor
29642964
if (T->isNullPtrType()) {
29652965
S.Diag(KernelInvocationFuncLoc,
29662966
diag::err_invalid_std_type_in_sycl_kernel)
2967-
<< KernelNameType << T;
2967+
<< KernelNameType << T->getAsTagDecl();
29682968

29692969
IsInvalid = true;
29702970
}
@@ -3008,12 +3008,12 @@ class SYCLKernelNameTypeVisitor
30083008

30093009
// Loop through Declaration Contexts to detect kernel names nested inside
30103010
// "std" and "anonymous" namespaces.
3011-
while (!DeclCtx->isTranslationUnit()) {
3011+
while (!DeclCtx->isTranslationUnit() && isa<NamespaceDecl>(DeclCtx)) {
30123012
const auto *NSDecl = dyn_cast<NamespaceDecl>(DeclCtx);
30133013
if (NSDecl && NSDecl->isStdNamespace()) {
30143014
S.Diag(KernelInvocationFuncLoc,
30153015
diag::err_invalid_std_type_in_sycl_kernel)
3016-
<< KernelNameType << QualType(Tag->getTypeForDecl(), 0);
3016+
<< KernelNameType << Tag;
30173017
IsInvalid = true;
30183018
return;
30193019
}

clang/test/SemaSYCL/implicit_kernel_type.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify %s -Wsycl-strict -DWARN
33
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsycl-unnamed-lambda -fsyntax-only -sycl-std=2020 -verify %s -Werror=sycl-strict
44

5+
// This test verifies that incorrect kernel names are diagnosed correctly.
6+
57
#include "sycl.hpp"
68

79
#ifdef __SYCL_UNNAMED_LAMBDA__
@@ -25,12 +27,10 @@ int main() {
2527
queue q;
2628

2729
#if defined(WARN)
28-
// expected-error@Inputs/sycl.hpp:220 {{'InvalidKernelName1' is an invalid kernel name type}}
29-
// expected-note@Inputs/sycl.hpp:220 {{'InvalidKernelName1' should be globally-visible}}
30-
// expected-note@+8 {{in instantiation of function template specialization}}
30+
// expected-error@Inputs/sycl.hpp:220 {{'InvalidKernelName1' should be globally-visible}}
31+
// expected-note@+7 {{in instantiation of function template specialization}}
3132
#elif defined(ERROR)
32-
// expected-error@Inputs/sycl.hpp:220 {{'InvalidKernelName1' is an invalid kernel name type}}
33-
// expected-note@Inputs/sycl.hpp:220 {{'InvalidKernelName1' should be globally-visible}}
33+
// expected-error@Inputs/sycl.hpp:220 {{'InvalidKernelName1' should be globally-visible}}
3434
// expected-note@+4 {{in instantiation of function template specialization}}
3535
#endif
3636
class InvalidKernelName1 {};

clang/test/SemaSYCL/kernelname-enum.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify %s
22

3-
#include "Inputs/sycl.hpp"
3+
// This test verifies that kernel names containing unscoped enums are diagnosed correctly.
4+
5+
#include "sycl.hpp"
46

57
enum unscoped_enum_int : int {
68
val_1,
@@ -67,15 +69,13 @@ int main() {
6769
});
6870

6971
q.submit([&](cl::sycl::handler &cgh) {
70-
// expected-error@Inputs/sycl.hpp:220 {{'dummy_functor_2<val_3>' is an invalid kernel name type}}
71-
// expected-note@Inputs/sycl.hpp:220 {{unscoped enum 'unscoped_enum_no_type_set' requires fixed underlying type}}
72+
// expected-error@Inputs/sycl.hpp:220 {{unscoped enum 'dummy_functor_2<val_3>' requires fixed underlying type}}
7273
// expected-note@+1{{in instantiation of function template specialization}}
7374
cgh.single_task(f2);
7475
});
7576

7677
q.submit([&](cl::sycl::handler &cgh) {
77-
// expected-error@Inputs/sycl.hpp:220 {{'templated_functor<dummy_functor_2>' is an invalid kernel name type}}
78-
// expected-note@Inputs/sycl.hpp:220 {{unscoped enum 'unscoped_enum_no_type_set' requires fixed underlying type}}
78+
// expected-error@Inputs/sycl.hpp:220 {{unscoped enum 'templated_functor<dummy_functor_2>' requires fixed underlying type}}
7979
// expected-note@+1{{in instantiation of function template specialization}}
8080
cgh.single_task(f5);
8181
});

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify %s
22

3+
// This test verifies that kernel names nested in 'std' and anonymous namespaces are correctly diagnosed.
4+
35
#include "sycl.hpp"
46

57
namespace std {
@@ -8,12 +10,6 @@ struct NestedStruct {};
810
}; // namespace NestedInStd
911
}; // namespace std
1012

11-
namespace NestedInStd {
12-
namespace std {
13-
struct NestedStruct {};
14-
}; // namespace std
15-
}; // namespace NestedInStd
16-
1713
namespace {
1814
namespace NestedInAnon {
1915
struct StructInAnonymousNS {};
@@ -36,10 +32,20 @@ struct MyWrapper {
3632
void test() {
3733
cl::sycl::queue q;
3834

35+
// expected-error@Inputs/sycl.hpp:220 {{'std::NestedInStd::NestedStruct' is an invalid kernel name, 'std::NestedInStd::NestedStruct' is declared in the 'std' namespace}}
36+
// expected-note@+2{{in instantiation of function template specialization}}
3937
q.submit([&](cl::sycl::handler &h) {
4038
h.single_task<std::NestedInStd::NestedStruct>([] {});
4139
});
4240

41+
// expected-error@Inputs/sycl.hpp:220 {{'Named::(anonymous namespace)::IsThisValid' should be globally-visibl}}
42+
// expected-note@+2{{in instantiation of function template specialization}}
43+
q.submit([&](cl::sycl::handler &h) {
44+
h.single_task<Named::IsThisValid>([] {});
45+
});
46+
47+
// expected-error@Inputs/sycl.hpp:220 {{'(anonymous namespace)::NestedInAnon::StructInAnonymousNS' should be globally-visible}}
48+
// expected-note@+2{{in instantiation of function template specialization}}
4349
q.submit([&](cl::sycl::handler &h) {
4450
h.single_task<NestedInAnon::StructInAnonymousNS>([] {});
4551
});

clang/test/SemaSYCL/unnamed-kernel.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
2-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-unnamed-lambda -fsyntax-only -Wno-sycl-2017-compat -verify %s
3-
#include "Inputs/sycl.hpp"
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -verify %s
2+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsycl-unnamed-lambda -fsyntax-only -sycl-std=2020 -verify %s
3+
4+
#include "sycl.hpp"
45

56
#ifdef __SYCL_UNNAMED_LAMBDA__
67
// expected-no-diagnostics
@@ -32,21 +33,36 @@ struct MyWrapper {
3233
public:
3334
void test() {
3435
cl::sycl::queue q;
35-
36+
#ifndef __SYCL_UNNAMED_LAMBDA__
37+
// expected-error@Inputs/sycl.hpp:220 {{'InvalidKernelName1' should be globally-visible}}
38+
// expected-note@+4{{in instantiation of function template specialization}}
39+
#endif
3640
class InvalidKernelName1 {};
3741
q.submit([&](cl::sycl::handler &h) {
3842
h.single_task<InvalidKernelName1>([] {});
3943
});
4044

45+
#ifndef __SYCL_UNNAMED_LAMBDA__
46+
// expected-error@Inputs/sycl.hpp:220 {{'namespace1::KernelName<InvalidKernelName2>' should be globally-visible}}
47+
// expected-note@+4{{in instantiation of function template specialization}}
48+
#endif
4149
class InvalidKernelName2 {};
4250
q.submit([&](cl::sycl::handler &h) {
4351
h.single_task<namespace1::KernelName<InvalidKernelName2>>([] {});
4452
});
4553

54+
#ifndef __SYCL_UNNAMED_LAMBDA__
55+
// expected-error@Inputs/sycl.hpp:220 {{'MyWrapper::InvalidKernelName0' should be globally-visible}}
56+
// expected-note@+3{{in instantiation of function template specialization}}
57+
#endif
4658
q.submit([&](cl::sycl::handler &h) {
4759
h.single_task<InvalidKernelName0>([] {});
4860
});
4961

62+
#ifndef __SYCL_UNNAMED_LAMBDA__
63+
// expected-error@Inputs/sycl.hpp:220 {{'namespace1::KernelName<MyWrapper::InvalidKernelName3>' should be globally-visible}}
64+
// expected-note@+3{{in instantiation of function template specialization}}
65+
#endif
5066
q.submit([&](cl::sycl::handler &h) {
5167
h.single_task<namespace1::KernelName<InvalidKernelName3>>([] {});
5268
});
@@ -56,22 +72,35 @@ struct MyWrapper {
5672
h.single_task<ValidAlias>([] {});
5773
});
5874

75+
#ifndef __SYCL_UNNAMED_LAMBDA__
76+
// expected-error@Inputs/sycl.hpp:220 {{'std::max_align_t' is an invalid kernel name, 'std::(anonymous)' is declared in the 'std' namespace}}
77+
// expected-note@+3{{in instantiation of function template specialization}}
78+
#endif
5979
q.submit([&](cl::sycl::handler &h) {
6080
h.single_task<std::max_align_t>([] {});
6181
});
6282

6383
using InvalidAlias = InvalidKernelName4;
64-
84+
#ifndef __SYCL_UNNAMED_LAMBDA__
85+
// expected-error@Inputs/sycl.hpp:220 {{'MyWrapper::InvalidKernelName4' should be globally-visible}}
86+
// expected-note@+3{{in instantiation of function template specialization}}
87+
#endif
6588
q.submit([&](cl::sycl::handler &h) {
6689
h.single_task<InvalidAlias>([] {});
6790
});
6891

6992
using InvalidAlias1 = InvalidKernelName5;
70-
93+
#ifndef __SYCL_UNNAMED_LAMBDA__
94+
// expected-error@Inputs/sycl.hpp:220 {{'namespace1::KernelName<MyWrapper::InvalidKernelName5>' should be globally-visible}}
95+
// expected-note@+3{{in instantiation of function template specialization}}
96+
#endif
7197
q.submit([&](cl::sycl::handler &h) {
7298
h.single_task<namespace1::KernelName<InvalidAlias1>>([] {});
7399
});
74-
100+
#ifndef __SYCL_UNNAMED_LAMBDA__
101+
// expected-error@Inputs/sycl.hpp:220 {{'Templated_kernel_name2<Templated_kernel_name<InvalidKernelName1>>' should be globally-visible}}
102+
// expected-note@+3{{in instantiation of function template specialization}}
103+
#endif
75104
q.submit([&](cl::sycl::handler &h) {
76105
h.single_task<Templated_kernel_name2<Templated_kernel_name<InvalidKernelName1>>>([] {});
77106
});
@@ -80,8 +109,11 @@ struct MyWrapper {
80109

81110
int main() {
82111
cl::sycl::queue q;
83-
112+
#ifndef __SYCL_UNNAMED_LAMBDA__
113+
// expected-error@Inputs/sycl.hpp:220 {{type cannot be unnamed}}
114+
// expected-note@+2{{in instantiation of function template specialization}}
115+
#endif
84116
q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); });
85117

86118
return 0;
87-
}
119+
}

0 commit comments

Comments
 (0)