blob: ba63f6d8c0f5f134f33c06552422a66cac1905a5 [file] [log] [blame]
Artem Belevich85b6f632016-05-19 20:13:39 +00001// REQUIRES: nvptx-registered-target
2
3// Make sure we don't allow dynamic initialization for device
4// variables, but accept empty constructors allowed by CUDA.
5
6// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
7// RUN: -I %S/.. -fsyntax-only -verify -o /dev/null %s
8
9// Counterpart in CodeGen covers valid cases that pass Sema
10// checks. Here we'll only cover cases that trigger errors.
11#include "CodeGenCUDA/device-var-init.cu"
12
13__shared__ int s_v_i = 1;
14// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
15
16__device__ int d_v_f = f();
17// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
18__shared__ int s_v_f = f();
19// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
20__constant__ int c_v_f = f();
21// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
22
23__shared__ T s_t_i = {2};
24// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
25
26__device__ EC d_ec_i(3);
27// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
28__shared__ EC s_ec_i(3);
29// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
30__constant__ EC c_ec_i(3);
31// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
32
33__device__ EC d_ec_i2 = {3};
34// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
35__shared__ EC s_ec_i2 = {3};
36// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
37__constant__ EC c_ec_i2 = {3};
38// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
39
40__device__ ETC d_etc_i(3);
41// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
42__shared__ ETC s_etc_i(3);
43// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
44__constant__ ETC c_etc_i(3);
45// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
46
47__device__ ETC d_etc_i2 = {3};
48// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
49__shared__ ETC s_etc_i2 = {3};
50// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
51__constant__ ETC c_etc_i2 = {3};
52// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
53
54__device__ UC d_uc;
55// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
56__shared__ UC s_uc;
57// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
58__constant__ UC c_uc;
59// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
60
Artem Belevich3650bbe2016-05-19 20:13:53 +000061__device__ UD d_ud;
62// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
63__shared__ UD s_ud;
64// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
65__constant__ UD c_ud;
66// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
67
Artem Belevich85b6f632016-05-19 20:13:39 +000068__device__ ECI d_eci;
69// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
70__shared__ ECI s_eci;
71// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
72__constant__ ECI c_eci;
73// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
74
75__device__ NEC d_nec;
76// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
77__shared__ NEC s_nec;
78// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
79__constant__ NEC c_nec;
80// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
81
Artem Belevich3650bbe2016-05-19 20:13:53 +000082__device__ NED d_ned;
83// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
84__shared__ NED s_ned;
85// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
86__constant__ NED c_ned;
87// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
88
Artem Belevich85b6f632016-05-19 20:13:39 +000089__device__ NCV d_ncv;
90// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
91__shared__ NCV s_ncv;
92// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
93__constant__ NCV c_ncv;
94// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
95
Artem Belevich3650bbe2016-05-19 20:13:53 +000096__device__ VD d_vd;
97// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
98__shared__ VD s_vd;
99// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
100__constant__ VD c_vd;
101// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
102
Artem Belevich85b6f632016-05-19 20:13:39 +0000103__device__ NCF d_ncf;
104// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
105__shared__ NCF s_ncf;
106// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
107__constant__ NCF c_ncf;
108// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
109
110__shared__ NCFS s_ncfs;
111// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
112
113__device__ UTC d_utc;
114// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
115__shared__ UTC s_utc;
116// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
117__constant__ UTC c_utc;
118// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
119
120__device__ UTC d_utc_i(3);
121// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
122__shared__ UTC s_utc_i(3);
123// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
124__constant__ UTC c_utc_i(3);
125// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
126
127__device__ NETC d_netc;
128// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
129__shared__ NETC s_netc;
130// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
131__constant__ NETC c_netc;
132// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
133
134__device__ NETC d_netc_i(3);
135// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
136__shared__ NETC s_netc_i(3);
137// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
138__constant__ NETC c_netc_i(3);
139// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
140
141__device__ EC_I_EC1 d_ec_i_ec1;
142// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
143__shared__ EC_I_EC1 s_ec_i_ec1;
144// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
145__constant__ EC_I_EC1 c_ec_i_ec1;
146// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
147
148__device__ T_V_T d_t_v_t;
149// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
150__shared__ T_V_T s_t_v_t;
151// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
152__constant__ T_V_T c_t_v_t;
153// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
154
155__device__ T_B_NEC d_t_b_nec;
156// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
157__shared__ T_B_NEC s_t_b_nec;
158// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
159__constant__ T_B_NEC c_t_b_nec;
160// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
161
162__device__ T_F_NEC d_t_f_nec;
163// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
164__shared__ T_F_NEC s_t_f_nec;
165// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
166__constant__ T_F_NEC c_t_f_nec;
167// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
168
169__device__ T_FA_NEC d_t_fa_nec;
170// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
171__shared__ T_FA_NEC s_t_fa_nec;
172// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
173__constant__ T_FA_NEC c_t_fa_nec;
174// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
175
Artem Belevich3650bbe2016-05-19 20:13:53 +0000176__device__ T_B_NED d_t_b_ned;
177// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
178__shared__ T_B_NED s_t_b_ned;
179// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
180__constant__ T_B_NED c_t_b_ned;
181// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
182
183__device__ T_F_NED d_t_f_ned;
184// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
185__shared__ T_F_NED s_t_f_ned;
186// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
187__constant__ T_F_NED c_t_f_ned;
188// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
189
190__device__ T_FA_NED d_t_fa_ned;
191// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
192__shared__ T_FA_NED s_t_fa_ned;
193// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
194__constant__ T_FA_NED c_t_fa_ned;
195// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
196
197// Verify that only __shared__ local variables may be static on device
198// side and that they are not allowed to be initialized.
Artem Belevich85b6f632016-05-19 20:13:39 +0000199__device__ void df_sema() {
200 static __shared__ NCFS s_ncfs;
201 // expected-error@-1 {{initialization is not supported for __shared__ variables.}}
202 static __shared__ UC s_uc;
203 // expected-error@-1 {{initialization is not supported for __shared__ variables.}}
Artem Belevich3650bbe2016-05-19 20:13:53 +0000204 static __shared__ NED s_ned;
205 // expected-error@-1 {{initialization is not supported for __shared__ variables.}}
206
Artem Belevich85b6f632016-05-19 20:13:39 +0000207 static __device__ int ds;
208 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
209 static __constant__ int dc;
210 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
211 static int v;
212 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
213}