1
1
// RUN: %clang_cc1 -fsycl-is-device -std=c++17 -sycl-std=2020 -verify %s
2
2
#include " Inputs/sycl.hpp"
3
3
4
- // Test cases below check for valid usage of device_global and
5
- // global_variable_allowed attributes, and that they are being correctly
6
- // generated in the AST.
4
+ // Diagnostic tests for device_global and global_variable_allowed attribute.
5
+
6
+ // Test that there are no errors when variables of type device_global are
7
+ // decorated with global_variable_allowed attribute appropriately.
7
8
using namespace sycl ::ext::oneapi;
8
9
9
10
device_global<int > glob; // OK
@@ -18,19 +19,95 @@ device_global<char> Foo::d;
18
19
19
20
struct Baz {
20
21
private:
21
- // expected-error@+1{{'device_global' member variable 'f' is not publicly accessible from namespace scope}}
22
+ // expected-error@+1{{'device_global' member variable 'f' should be publicly accessible from namespace scope}}
22
23
static device_global<int > f;
24
+
25
+ protected:
26
+ // expected-error@+1{{'device_global' member variable 'g' should be publicly accessible from namespace scope}}
27
+ static device_global<int > g;
23
28
};
29
+
24
30
device_global<int > Baz::f;
25
31
26
32
device_global<int [4 ]> not_array; // OK
27
33
34
+ // expected-error@+1{{'device_global' array is not allowed}}
35
+ device_global<int > array[4 ];
36
+
28
37
device_global<int > same_name; // OK
38
+
29
39
namespace foo {
30
40
device_global<int > same_name; // OK
31
41
}
32
- namespace {
33
- device_global<int > same_name; // OK
42
+
43
+ struct BBar {
44
+ private:
45
+ struct BarInsider {
46
+ // expected-error@+1{{'device_global' member variable 'c' should be publicly accessible from namespace scope}}
47
+ static device_global<float > c;
48
+ };
49
+
50
+ protected:
51
+ struct BarInsiderProtected {
52
+ // expected-error@+1{{'device_global' member variable 'c' should be publicly accessible from namespace scope}}
53
+ static device_global<float > c;
54
+ };
55
+ };
56
+
57
+ struct ABar {
58
+ void method () {
59
+ // expected-error@+1{{'device_global' variable must be a static data member or declared in global or namespace scope}}
60
+ static device_global<float > c;
61
+ }
62
+ struct BarInsider {
63
+ static device_global<float > c;
64
+ void method () {
65
+ // expected-error@+1{{'device_global' variable must be a static data member or declared in global or namespace scope}}
66
+ static device_global<float > c;
67
+ }
68
+ };
69
+ };
70
+
71
+ template <typename T> void fooBar () {
72
+ // expected-error@+1{{'device_global' variable must be a static data member or declared in global or namespace scope}}
73
+ static device_global<T> c;
74
+ // expected-error@+1{{'device_global' variable must be a static data member or declared in global or namespace scope}}
75
+ device_global<T> d;
76
+ }
77
+
78
+ template <typename T> struct TS {
79
+ private:
80
+ // expected-error@+1 2{{'device_global' member variable 'a' should be publicly accessible from namespace scope}}
81
+ static device_global<T> a;
82
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
83
+ device_global<T> b;
84
+ // expected-error@+2{{'device_global' member variable 'c' should be publicly accessible from namespace scope}}
85
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
86
+ device_global<int > c;
87
+
88
+ public:
89
+ static device_global<T> d;
90
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
91
+ device_global<T> e;
92
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
93
+ device_global<int > f;
94
+
95
+ protected:
96
+ // expected-error@+1 2{{'device_global' member variable 'g' should be publicly accessible from namespace scope}}
97
+ static device_global<T> g;
98
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
99
+ device_global<T> h;
100
+ // expected-error@+2{{'device_global' member variable 'i' should be publicly accessible from namespace scope}}
101
+ // expected-error@+1 2{{'device_global' variable must be a static data member or declared in global or namespace scope}}
102
+ device_global<int > i;
103
+ };
104
+
105
+ // expected-note@+1{{in instantiation of template class 'TS<int>' requested here}}
106
+ TS<int > AAAA;
107
+
108
+ // expected-note@+2{{in instantiation of template class 'TS<char>' requested here}}
109
+ template <typename T> void templFoo () {
110
+ TS<T> Var;
34
111
}
35
112
36
113
// expected-error@+2{{'device_global' attribute only applies to classes}}
@@ -44,6 +121,12 @@ device_global<int> same_name; // OK
44
121
union [[__sycl_detail__::device_global]] [[__sycl_detail__::global_variable_allowed]] a_union;
45
122
46
123
int main () {
124
+ // expected-note@+1{{in instantiation of function template specialization 'templFoo<char>' requested here}}
125
+ templFoo<char >();
126
+
127
+ // expected-note@+1{{in instantiation of function template specialization 'fooBar<int>' requested here}}
128
+ fooBar<int >();
129
+
47
130
sycl::kernel_single_task<class KernelName1 >([=]() {
48
131
(void )glob;
49
132
(void )static_glob;
@@ -53,11 +136,7 @@ int main() {
53
136
});
54
137
55
138
sycl::kernel_single_task<class KernelName2 >([]() {
56
- // expected-error@+1{{'device_global' variables must be static or declared at namespace scope}}
139
+ // expected-error@+1{{'device_global' variable must be a static data member or declared in global or namespace scope}}
57
140
device_global<int > non_static;
58
-
59
- // expect no error on non_const_static declaration if decorated with
60
- // [[__sycl_detail__::global_variable_allowed]]
61
- static device_global<int > non_const_static;
62
141
});
63
142
}
0 commit comments