Artem Belevich | 85b6f63 | 2016-05-19 20:13:39 +0000 | [diff] [blame^] | 1 | // 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 | } |