blob: c717a3346330077164a712ac37237d7737c01edd [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
61__device__ ECI d_eci;
62// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
63__shared__ ECI s_eci;
64// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
65__constant__ ECI c_eci;
66// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
67
68__device__ NEC d_nec;
69// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
70__shared__ NEC s_nec;
71// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
72__constant__ NEC c_nec;
73// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
74
75__device__ NCV d_ncv;
76// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
77__shared__ NCV s_ncv;
78// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
79__constant__ NCV c_ncv;
80// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
81
82__device__ NCF d_ncf;
83// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
84__shared__ NCF s_ncf;
85// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
86__constant__ NCF c_ncf;
87// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
88
89__shared__ NCFS s_ncfs;
90// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
91
92__device__ UTC d_utc;
93// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
94__shared__ UTC s_utc;
95// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
96__constant__ UTC c_utc;
97// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
98
99__device__ UTC d_utc_i(3);
100// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
101__shared__ UTC s_utc_i(3);
102// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
103__constant__ UTC c_utc_i(3);
104// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
105
106__device__ NETC d_netc;
107// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
108__shared__ NETC s_netc;
109// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
110__constant__ NETC c_netc;
111// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
112
113__device__ NETC d_netc_i(3);
114// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
115__shared__ NETC s_netc_i(3);
116// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
117__constant__ NETC c_netc_i(3);
118// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
119
120__device__ EC_I_EC1 d_ec_i_ec1;
121// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
122__shared__ EC_I_EC1 s_ec_i_ec1;
123// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
124__constant__ EC_I_EC1 c_ec_i_ec1;
125// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
126
127__device__ T_V_T d_t_v_t;
128// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
129__shared__ T_V_T s_t_v_t;
130// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
131__constant__ T_V_T c_t_v_t;
132// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
133
134__device__ T_B_NEC d_t_b_nec;
135// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
136__shared__ T_B_NEC s_t_b_nec;
137// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
138__constant__ T_B_NEC c_t_b_nec;
139// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
140
141__device__ T_F_NEC d_t_f_nec;
142// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
143__shared__ T_F_NEC s_t_f_nec;
144// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
145__constant__ T_F_NEC c_t_f_nec;
146// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
147
148__device__ T_FA_NEC d_t_fa_nec;
149// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
150__shared__ T_FA_NEC s_t_fa_nec;
151// expected-error@-1 {{initialization is not supported for __shared__ variables.}}
152__constant__ T_FA_NEC c_t_fa_nec;
153// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
154
155// Make sure that initialization restrictions do not apply to local
156// variables.
157__device__ void df_sema() {
158 static __shared__ NCFS s_ncfs;
159 // expected-error@-1 {{initialization is not supported for __shared__ variables.}}
160 static __shared__ UC s_uc;
161 // expected-error@-1 {{initialization is not supported for __shared__ variables.}}
162 static __device__ int ds;
163 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
164 static __constant__ int dc;
165 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
166 static int v;
167 // expected-error@-1 {{Within a __device__/__global__ function, only __shared__ variables may be marked "static"}}
168}