1 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL2.0 2 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL2.0 3 // RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL2.0 4 5 /* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to 6 * different address spaces, mainly described in Sections 6.5.5 and 6.5.6. 7 * 8 * It adds notion of overlapping address spaces. The main differention is that 9 * an unnamed address space is added, called '__generic'. Pointers to the 10 * generic address space can be interchangabley used with pointers to any 11 * other address space except for __constant address space (Section 6.5.5). 12 * 13 * Based on this there are 3 sets of tests: __generic, named (__global in this 14 * case), and __constant, that should cover all program paths for CL address 15 * space conversions used in initialisations, assignments, casts, comparisons 16 * and arithmetic operations. 17 */ 18 19 #ifdef GENERIC 20 #define AS generic 21 #endif 22 23 #ifdef GLOBAL 24 #define AS global 25 #endif 26 27 #ifdef CONSTANT 28 #define AS constant 29 #endif 30 31 void f_glob(global int *arg_glob) {} 32 #ifndef GLOBAL 33 // expected-note@-2{{passing argument to parameter 'arg_glob' here}} 34 #endif 35 36 void f_loc(local int *arg_loc) { 37 } // expected-note@-1{{passing argument to parameter 'arg_loc' here}} 38 39 void f_const(constant int *arg_const) {} 40 #ifndef CONSTANT 41 // expected-note@-2{{passing argument to parameter 'arg_const' here}} 42 #endif 43 44 void f_priv(private int *arg_priv) { 45 } // expected-note@-1{{passing argument to parameter 'arg_priv' here}} 46 47 void f_gen(generic int *arg_gen) {} 48 #ifdef CONSTANT 49 // expected-note@-2{{passing argument to parameter 'arg_gen' here}} 50 #endif 51 52 void test_conversion(global int *arg_glob, local int *arg_loc, 53 constant int *arg_const, private int *arg_priv, 54 generic int *arg_gen) { 55 56 AS int *var_init1 = arg_glob; 57 #ifdef CONSTANT 58 // expected-error@-2{{initializing '__constant int *' with an expression of type '__global int *' changes address space of pointer}} 59 #endif 60 61 AS int *var_init2 = arg_loc; 62 #ifndef GENERIC 63 // expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__local int *' changes address space of pointer}} 64 #endif 65 66 AS int *var_init3 = arg_const; 67 #ifndef CONSTANT 68 // expected-error-re@-2{{initializing '__{{global|generic}} int *' with an expression of type '__constant int *' changes address space of pointer}} 69 #endif 70 71 AS int *var_init4 = arg_priv; 72 #ifndef GENERIC 73 // expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}} 74 #endif 75 76 AS int *var_init5 = arg_gen; 77 #ifndef GENERIC 78 // expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__generic int *' changes address space of pointer}} 79 #endif 80 81 AS int *var_cast1 = (AS int *)arg_glob; 82 #ifdef CONSTANT 83 // expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}} 84 #endif 85 86 AS int *var_cast2 = (AS int *)arg_loc; 87 #ifndef GENERIC 88 // expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} 89 #endif 90 91 AS int *var_cast3 = (AS int *)arg_const; 92 #ifndef CONSTANT 93 // expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} 94 #endif 95 96 AS int *var_cast4 = (AS int *)arg_priv; 97 #ifndef GENERIC 98 // expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} 99 #endif 100 101 AS int *var_cast5 = (AS int *)arg_gen; 102 #ifdef CONSTANT 103 // expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} 104 #endif 105 106 AS int *var_impl; 107 var_impl = arg_glob; 108 #ifdef CONSTANT 109 // expected-error@-2{{assigning '__global int *' to '__constant int *' changes address space of pointer}} 110 #endif 111 112 var_impl = arg_loc; 113 #ifndef GENERIC 114 // expected-error-re@-2{{assigning '__local int *' to '__{{global|constant}} int *' changes address space of pointer}} 115 #endif 116 117 var_impl = arg_const; 118 #ifndef CONSTANT 119 // expected-error-re@-2{{assigning '__constant int *' to '__{{global|generic}} int *' changes address space of pointer}} 120 #endif 121 122 var_impl = arg_priv; 123 #ifndef GENERIC 124 // expected-error-re@-2{{assigning 'int *' to '__{{global|constant}} int *' changes address space of pointer}} 125 #endif 126 127 var_impl = arg_gen; 128 #ifndef GENERIC 129 // expected-error-re@-2{{assigning '__generic int *' to '__{{global|constant}} int *' changes address space of pointer}} 130 #endif 131 132 var_cast1 = (AS int *)arg_glob; 133 #ifdef CONSTANT 134 // expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}} 135 #endif 136 137 var_cast2 = (AS int *)arg_loc; 138 #ifndef GENERIC 139 // expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} 140 #endif 141 142 var_cast3 = (AS int *)arg_const; 143 #ifndef CONSTANT 144 // expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} 145 #endif 146 147 var_cast4 = (AS int *)arg_priv; 148 #ifndef GENERIC 149 // expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} 150 #endif 151 152 var_cast5 = (AS int *)arg_gen; 153 #ifdef CONSTANT 154 // expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} 155 #endif 156 157 AS int *var_cmp; 158 int b = var_cmp != arg_glob; 159 #ifdef CONSTANT 160 // expected-error@-2{{comparison between ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 161 #endif 162 163 b = var_cmp != arg_loc; 164 #ifndef GENERIC 165 // expected-error-re@-2{{comparison between ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 166 #endif 167 168 b = var_cmp == arg_const; 169 #ifndef CONSTANT 170 // expected-error-re@-2{{comparison between ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 171 #endif 172 173 b = var_cmp <= arg_priv; 174 #ifndef GENERIC 175 // expected-error-re@-2{{comparison between ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 176 #endif 177 178 b = var_cmp >= arg_gen; 179 #ifdef CONSTANT 180 // expected-error@-2{{comparison between ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 181 #endif 182 183 AS int *var_sub; 184 b = var_sub - arg_glob; 185 #ifdef CONSTANT 186 // expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 187 #endif 188 189 b = var_sub - arg_loc; 190 #ifndef GENERIC 191 // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 192 #endif 193 194 b = var_sub - arg_const; 195 #ifndef CONSTANT 196 // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 197 #endif 198 199 b = var_sub - arg_priv; 200 #ifndef GENERIC 201 // expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 202 #endif 203 204 b = var_sub - arg_gen; 205 #ifdef CONSTANT 206 // expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 207 #endif 208 209 f_glob(var_sub); 210 #ifndef GLOBAL 211 // expected-error-re@-2{{passing '__{{constant|generic}} int *' to parameter of type '__global int *' changes address space of pointer}} 212 #endif 213 214 f_loc(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type '__local int *' changes address space of pointer}} 215 216 f_const(var_sub); 217 #ifndef CONSTANT 218 // expected-error-re@-2{{passing '__{{global|generic}} int *' to parameter of type '__constant int *' changes address space of pointer}} 219 #endif 220 221 f_priv(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type 'int *' changes address space of pointer}} 222 223 f_gen(var_sub); 224 #ifdef CONSTANT 225 // expected-error@-2{{passing '__constant int *' to parameter of type '__generic int *' changes address space of pointer}} 226 #endif 227 } 228 229 void test_ternary() { 230 AS int *var_cond; 231 generic int *var_gen; 232 global int *var_glob; 233 var_gen = 0 ? var_cond : var_glob; 234 #ifdef CONSTANT 235 // expected-error@-2{{conditional operator with the second and third operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 236 #endif 237 238 local int *var_loc; 239 var_gen = 0 ? var_cond : var_loc; 240 #ifndef GENERIC 241 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 242 #endif 243 244 constant int *var_const; 245 var_cond = 0 ? var_cond : var_const; 246 #ifndef CONSTANT 247 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 248 #endif 249 250 private int *var_priv; 251 var_gen = 0 ? var_cond : var_priv; 252 #ifndef GENERIC 253 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 254 #endif 255 256 var_gen = 0 ? var_cond : var_gen; 257 #ifdef CONSTANT 258 // expected-error@-2{{conditional operator with the second and third operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 259 #endif 260 261 void *var_void_gen; 262 global char *var_glob_ch; 263 var_void_gen = 0 ? var_cond : var_glob_ch; 264 #ifdef CONSTANT 265 // expected-error@-2{{conditional operator with the second and third operands of type ('__constant int *' and '__global char *') which are pointers to non-overlapping address spaces}} 266 #endif 267 268 local char *var_loc_ch; 269 var_void_gen = 0 ? var_cond : var_loc_ch; 270 #ifndef GENERIC 271 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local char *') which are pointers to non-overlapping address spaces}} 272 #endif 273 274 constant void *var_void_const; 275 constant char *var_const_ch; 276 var_void_const = 0 ? var_cond : var_const_ch; 277 #ifndef CONSTANT 278 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant char *') which are pointers to non-overlapping address spaces}} 279 #endif 280 281 private char *var_priv_ch; 282 var_void_gen = 0 ? var_cond : var_priv_ch; 283 #ifndef GENERIC 284 // expected-error-re@-2{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'char *') which are pointers to non-overlapping address spaces}} 285 #endif 286 287 generic char *var_gen_ch; 288 var_void_gen = 0 ? var_cond : var_gen_ch; 289 #ifdef CONSTANT 290 // expected-error@-2{{conditional operator with the second and third operands of type ('__constant int *' and '__generic char *') which are pointers to non-overlapping address spaces}} 291 #endif 292 } 293 294