You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SYCL] Add warning for attributes applied to non-kernel functions (#15154)
According to [5.8.1. Kernel
attributes](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:kernel.attributes),
kernel attributes can only be applied to SYCL kernel functions, but not
to a regular device functions.
Based on this information, this pull request introduces a warning
diagnostic whenever specified attributes are applied to regular device
functions.
Copy file name to clipboardExpand all lines: clang/test/SemaSYCL/check-work-group-size-hint-device.cpp
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,8 @@
17
17
18
18
// Produce a conflicting attribute warning when the args are different.
19
19
[[sycl::work_group_size_hint(4, 1, 1)]] voidf3(); // expected-note {{previous attribute is here}}
20
-
[[sycl::work_group_size_hint(1, 1, 32)]] voidf3() {} // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}}
20
+
[[sycl::work_group_size_hint(1, 1, 32)]] voidf3() {} // expected-warning {{attribute 'work_group_size_hint' is already applied with different arguments}} \
21
+
// expected-warning {{'work_group_size_hint' attribute can only be applied to a SYCL kernel function}}
21
22
22
23
// 1 and 2 dim versions
23
24
[[sycl::work_group_size_hint(2)]] voidf4(); // ok
@@ -70,10 +71,13 @@ void instantiate() {
70
71
f8<0>(); // expected-note {{in instantiation}}
71
72
#endif
72
73
74
+
// expected-warning@#f9prev {{'work_group_size_hint' attribute can only be applied to a SYCL kernel function}}
73
75
f9<1, 1, 1>(); // OK, args are the same on the redecl.
74
76
75
77
// expected-warning@#f9 {{attribute 'work_group_size_hint' is already applied with different arguments}}
76
78
// expected-note@#f9prev {{previous attribute is here}}
79
+
// expected-warning@#f9prev {{'work_group_size_hint' attribute can only be applied to a SYCL kernel function}}
[[sycl::work_group_size_hint(4, 4, 4)]] voidoperator()() const {};// expected-warning {{'work_group_size_hint' attribute can only be applied to a SYCL kernel function}}
101
105
};
102
106
103
107
// Checking whether propagation of the attribute happens or not, according to the SYCL version.
104
108
#if defined(EXPECT_PROP) // if attribute is propagated, then we expect errors here
[[sycl::work_group_size_hint(8, 8, 8)]] voidf8x8x8(){};// expected-warning {{'work_group_size_hint' attribute can only be applied to a SYCL kernel function}}
Copy file name to clipboardExpand all lines: clang/test/SemaSYCL/device_has.cpp
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,6 @@ enum class aspect {
17
17
18
18
[[sycl::device_has("123")]] voidfunc1() {} // expected-error{{'device_has' attribute argument is invalid; argument must be device aspect of type sycl::aspect}}
19
19
[[sycl::device_has(fake_cl::sycl::aspect::aspect1)]] voidfunc2() {} // expected-error{{'device_has' attribute argument is invalid; argument must be device aspect of type sycl::aspect}}
20
-
21
20
[[sycl::device_has(sycl::aspect::cpu)]] voidfunc3(); // expected-note{{previous attribute is here}}
22
21
[[sycl::device_has(sycl::aspect::gpu)]] voidfunc3() {} // expected-warning{{attribute 'device_has' is already applied}}
Copy file name to clipboardExpand all lines: clang/test/SemaSYCL/intel-max-work-group-size.cpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -70,15 +70,15 @@ void instantiate() {
70
70
// a declaration along with [[sycl::reqd_work_group_size(X1, Y1, Z1)]]
71
71
// attribute, check to see if values of reqd_work_group_size arguments are
72
72
// equal or less than values coming from max_work_group_size attribute.
73
-
[[sycl::reqd_work_group_size(64, 64, 64)]] // expected-note {{conflicting attribute is here}}
73
+
[[sycl::reqd_work_group_size(64, 64, 64)]] // expected-note {{conflicting attribute is here}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
[[sycl::reqd_work_group_size(2, 2, 2)]] [[intel::max_work_group_size(4, 4, 4)]] voidf11() {} //expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
82
82
83
83
[[sycl::reqd_work_group_size(64, 64, 64)]] voidf12(); // expected-note {{conflicting attribute is here}}
[[cl::reqd_work_group_size(1, 2, 3)]] // expected-warning {{attribute 'cl::reqd_work_group_size' is deprecated}} \
94
-
// expected-note {{did you mean to use 'sycl::reqd_work_group_size' instead?}}
94
+
// expected-note {{did you mean to use 'sycl::reqd_work_group_size' instead?}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
95
95
[[intel::max_work_group_size(1, 2, 3)]] void
96
96
f15() {} // OK
97
97
98
98
[[intel::max_work_group_size(2, 3, 7)]] voidf16(); // expected-note {{conflicting attribute is here}}
[[intel::max_work_group_size(1, 2, 3)]] [[sycl::reqd_work_group_size(1, 2, 3)]] voidf17(){}; //expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
102
102
103
103
[[sycl::reqd_work_group_size(16)]] // expected-note {{conflicting attribute is here}}
[[intel::reqd_sub_group_size(16)]] SYCL_EXTERNAL voidB() {// expected-warning {{'reqd_sub_group_size' attribute can only be applied to a SYCL kernel function}}
40
41
A();
41
42
}
42
43
// expected-note@+1 {{conflicting attribute is here}}
[[intel::reqd_sub_group_size(2)]] voidsg_size2() {}// expected-warning {{'reqd_sub_group_size' attribute can only be applied to a SYCL kernel function}}
44
45
45
-
// expected-note@+2 {{conflicting attribute is here}}
46
-
// expected-error@+1 {{conflicting attributes applied to a SYCL kernel}}
46
+
// expected-note@+3 {{conflicting attribute is here}}
47
+
// expected-error@+2 {{conflicting attributes applied to a SYCL kernel}}
48
+
// expected-warning@+1 {{'reqd_sub_group_size' attribute can only be applied to a SYCL kernel function}}
[[sycl::reqd_work_group_size(32, 32, 32)]] voidf3(); // OK
30
31
31
32
// Produce a conflicting attribute warning when the args are different.
32
-
[[sycl::reqd_work_group_size(6, 6, 6)]] // expected-note {{previous attribute is here}}
33
+
[[sycl::reqd_work_group_size(6, 6, 6)]] // expected-note {{previous attribute is here}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
33
34
[[sycl::reqd_work_group_size(16, 16, 16)]] void// expected-error {{attribute 'reqd_work_group_size' is already applied with different arguments}}
34
35
f4() {}
35
36
36
37
// Catch the easy case where the attributes are all specified at once with
37
38
// different arguments.
38
39
structTRIFuncObjGood1 {
39
-
// expected-note@+2 {{previous attribute is here}}
40
-
// expected-error@+1 {{attribute 'reqd_work_group_size' is already applied with different arguments}}
40
+
// expected-note@+3 {{previous attribute is here}}
41
+
// expected-error@+2 {{attribute 'reqd_work_group_size' is already applied with different arguments}}
42
+
// expected-warning@+1 {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
[[sycl::reqd_work_group_size(4, 4)]] // expected-error {{attribute 'reqd_work_group_size' is already applied with different arguments}}
58
+
[[sycl::reqd_work_group_size(4, 4)]] // expected-error {{attribute 'reqd_work_group_size' is already applied with different arguments}} \
59
+
// expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
56
60
void
57
61
TRIFuncObjGood3::operator()() const {}
58
62
@@ -73,7 +77,7 @@ class FunctorC {
73
77
74
78
classFunctor32 {
75
79
public:
76
-
[[sycl::reqd_work_group_size(32, 1, 1)]] // expected-note {{previous attribute is here}}
80
+
[[sycl::reqd_work_group_size(32, 1, 1)]] // expected-note {{previous attribute is here}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
77
81
[[sycl::reqd_work_group_size(1, 1, 32)]] void// expected-error{{attribute 'reqd_work_group_size' is already applied with different arguments}}
78
82
operator()() const {}
79
83
};
@@ -105,16 +109,18 @@ void instantiate() {
105
109
f7<1, 1, 1>(); // OK, args are the same on the redecl.
106
110
// expected-error@#f7 {{attribute 'reqd_work_group_size' is already applied with different arguments}}
107
111
// expected-note@#f7prev {{previous attribute is here}}
112
+
// expected-warning@#f7prev {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
113
+
// expected-warning@#f7prev {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
// Tests for 'reqd_work_group_size' attribute duplication.
112
118
113
-
[[sycl::reqd_work_group_size(8)]] // expected-note {{previous attribute is here}}
119
+
[[sycl::reqd_work_group_size(8)]] // expected-note {{previous attribute is here}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
114
120
[[sycl::reqd_work_group_size(1, 1, 8)]] void// expected-error {{attribute 'reqd_work_group_size' is already applied with different arguments}}
115
121
f8(){};
116
122
117
-
[[sycl::reqd_work_group_size(32, 32, 1)]] // expected-note {{previous attribute is here}}
123
+
[[sycl::reqd_work_group_size(32, 32, 1)]] // expected-note {{previous attribute is here}} // expected-warning {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
118
124
[[sycl::reqd_work_group_size(32, 32)]] voidf9() {} // expected-error {{attribute 'reqd_work_group_size' is already applied with different arguments}}
119
125
120
126
// Test that template redeclarations also get diagnosed properly.
@@ -127,6 +133,8 @@ void test() {
127
133
f10<64, 1, 1>(); // OK, args are the same on the redecl.
128
134
// expected-error@#f10err {{attribute 'reqd_work_group_size' is already applied with different arguments}}
129
135
// expected-note@#f10prev {{previous attribute is here}}
136
+
// expected-warning@#f10prev {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
137
+
// expected-warning@#f10prev {{'reqd_work_group_size' attribute can only be applied to a SYCL kernel function}}
0 commit comments