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// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=c++ 5// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=c++ 6// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=c++ 7 8/* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to 9* different address spaces, mainly described in Sections 6.5.5 and 6.5.6. 10* 11* It adds notion of overlapping address spaces. The main differention is that 12* an unnamed address space is added, called '__generic'. Pointers to the 13* generic address space can be interchangabley used with pointers to any 14* other address space except for __constant address space (Section 6.5.5). 15* 16* Based on this there are 3 sets of tests: __generic, named (__global in this 17* case), and __constant, that should cover all program paths for CL address 18* space conversions used in initialisations, assignments, casts, comparisons 19* and arithmetic operations. 20*/ 21 22#ifdef GENERIC 23#define AS __generic 24#define AS_COMP __local 25#define AS_INCOMP __constant 26#endif 27 28#ifdef GLOBAL 29#define AS __global 30#define AS_COMP __global 31#define AS_INCOMP __local 32#endif 33 34#ifdef CONSTANT 35#define AS __constant 36#define AS_COMP __constant 37#define AS_INCOMP __global 38#endif 39 40void f_glob(__global int *arg_glob) {} 41#ifndef GLOBAL 42#if !__OPENCL_CPP_VERSION__ 43// expected-note@-3{{passing argument to parameter 'arg_glob' here}} 44#else 45// expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{generic|constant}} int *'), parameter type must be '__global int *'}} 46#endif 47#endif 48 49void f_loc(__local int *arg_loc) {} 50#if !__OPENCL_CPP_VERSION__ 51// expected-note@-2{{passing argument to parameter 'arg_loc' here}} 52#else 53// expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be '__local int *'}} 54#endif 55 56void f_const(__constant int *arg_const) {} 57#ifndef CONSTANT 58#if !__OPENCL_CPP_VERSION__ 59// expected-note@-3{{passing argument to parameter 'arg_const' here}} 60#else 61// expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic}} int *'), parameter type must be '__constant int *'}} 62#endif 63#endif 64 65void f_priv(__private int *arg_priv) {} 66#if !__OPENCL_CPP_VERSION__ 67// expected-note@-2{{passing argument to parameter 'arg_priv' here}} 68#else 69// expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be 'int *'}} 70#endif 71 72void f_gen(__generic int *arg_gen) {} 73#ifdef CONSTANT 74#if !__OPENCL_CPP_VERSION__ 75// expected-note@-3{{passing argument to parameter 'arg_gen' here}} 76#else 77// expected-note@-5{{candidate function not viable: address space mismatch in 1st argument ('__constant int *'), parameter type must be '__generic int *'}} 78#endif 79#endif 80 81void test_conversion(__global int *arg_glob, __local int *arg_loc, 82 __constant int *arg_const, __private int *arg_priv, 83 __generic int *arg_gen) { 84 85 AS int *var_init1 = arg_glob; 86#ifdef CONSTANT 87#if !__OPENCL_CPP_VERSION__ 88// expected-error@-3{{initializing '__constant int *' with an expression of type '__global int *' changes address space of pointer}} 89#else 90// expected-error@-5{{cannot initialize a variable of type '__constant int *' with an lvalue of type '__global int *'}} 91#endif 92#endif 93 94 AS int *var_init2 = arg_loc; 95#ifndef GENERIC 96#if !__OPENCL_CPP_VERSION__ 97// expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type '__local int *' changes address space of pointer}} 98#else 99// expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type '__local int *'}} 100#endif 101#endif 102 103 AS int *var_init3 = arg_const; 104#ifndef CONSTANT 105#if !__OPENCL_CPP_VERSION__ 106// expected-error-re@-3{{initializing '__{{global|generic}} int *' with an expression of type '__constant int *' changes address space of pointer}} 107#else 108// expected-error-re@-5{{cannot initialize a variable of type '__{{global|generic}} int *' with an lvalue of type '__constant int *'}} 109#endif 110#endif 111 112 AS int *var_init4 = arg_priv; 113#ifndef GENERIC 114#if !__OPENCL_CPP_VERSION__ 115// expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}} 116#else 117// expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type 'int *'}} 118#endif 119#endif 120 121 AS int *var_init5 = arg_gen; 122#ifndef GENERIC 123#if !__OPENCL_CPP_VERSION__ 124// expected-error-re@-3{{initializing '__{{global|constant}} int *' with an expression of type '__generic int *' changes address space of pointer}} 125#else 126// expected-error-re@-5{{cannot initialize a variable of type '__{{global|constant}} int *' with an lvalue of type '__generic int *'}} 127#endif 128#endif 129 130 AS int *var_cast1 = (AS int *)arg_glob; 131#ifdef CONSTANT 132// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}} 133#endif 134 135 AS int *var_cast2 = (AS int *)arg_loc; 136#ifndef GENERIC 137// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} 138#endif 139 140 AS int *var_cast3 = (AS int *)arg_const; 141#ifndef CONSTANT 142// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} 143#endif 144 145 AS int *var_cast4 = (AS int *)arg_priv; 146#ifndef GENERIC 147// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} 148#endif 149 150 AS int *var_cast5 = (AS int *)arg_gen; 151#ifdef CONSTANT 152// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} 153#endif 154 155 AS int *var_impl; 156 var_impl = arg_glob; 157#ifdef CONSTANT 158#if !__OPENCL_CPP_VERSION__ 159// expected-error@-3{{assigning '__global int *' to '__constant int *' changes address space of pointer}} 160#else 161// expected-error@-5{{assigning to '__constant int *' from incompatible type '__global int *'}} 162#endif 163#endif 164 165 var_impl = arg_loc; 166#ifndef GENERIC 167#if !__OPENCL_CPP_VERSION__ 168// expected-error-re@-3{{assigning '__local int *' to '__{{global|constant}} int *' changes address space of pointer}} 169#else 170// expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type '__local int *'}} 171#endif 172#endif 173 174 var_impl = arg_const; 175#ifndef CONSTANT 176#if !__OPENCL_CPP_VERSION__ 177// expected-error-re@-3{{assigning '__constant int *' to '__{{global|generic}} int *' changes address space of pointer}} 178#else 179// expected-error-re@-5{{assigning to '__{{global|generic}} int *' from incompatible type '__constant int *'}} 180#endif 181#endif 182 183 var_impl = arg_priv; 184#ifndef GENERIC 185#if !__OPENCL_CPP_VERSION__ 186// expected-error-re@-3{{assigning 'int *' to '__{{global|constant}} int *' changes address space of pointer}} 187#else 188// expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type 'int *'}} 189#endif 190#endif 191 192 var_impl = arg_gen; 193#ifndef GENERIC 194#if !__OPENCL_CPP_VERSION__ 195// expected-error-re@-3{{assigning '__generic int *' to '__{{global|constant}} int *' changes address space of pointer}} 196#else 197// expected-error-re@-5{{assigning to '__{{global|constant}} int *' from incompatible type '__generic int *'}} 198#endif 199#endif 200 201 var_cast1 = (AS int *)arg_glob; 202#ifdef CONSTANT 203// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}} 204#endif 205 206 var_cast2 = (AS int *)arg_loc; 207#ifndef GENERIC 208// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}} 209#endif 210 211 var_cast3 = (AS int *)arg_const; 212#ifndef CONSTANT 213// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}} 214#endif 215 216 var_cast4 = (AS int *)arg_priv; 217#ifndef GENERIC 218// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}} 219#endif 220 221 var_cast5 = (AS int *)arg_gen; 222#ifdef CONSTANT 223// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}} 224#endif 225 226 AS int *var_cmp; 227 int b = var_cmp != arg_glob; 228#ifdef CONSTANT 229#if !__OPENCL_CPP_VERSION__ 230// expected-error@-3{{comparison between ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 231#else 232// expected-error@-5{{comparison of distinct pointer types ('__constant int *' and '__global int *')}} 233#endif 234#endif 235 236 b = var_cmp != arg_loc; 237#ifndef GENERIC 238#if !__OPENCL_CPP_VERSION__ 239// expected-error-re@-3{{comparison between ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 240#else 241// expected-error-re@-5{{comparison of distinct pointer types ('__{{global|constant}} int *' and '__local int *')}} 242#endif 243#endif 244 245 b = var_cmp == arg_const; 246#ifndef CONSTANT 247#if !__OPENCL_CPP_VERSION__ 248// expected-error-re@-3{{comparison between ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 249#else 250// expected-error-re@-5{{comparison of distinct pointer types ('__{{global|generic}} int *' and '__constant int *')}} 251#endif 252#endif 253 254 b = var_cmp <= arg_priv; 255#ifndef GENERIC 256#if !__OPENCL_CPP_VERSION__ 257// expected-error-re@-3{{comparison between ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 258#else 259// expected-error-re@-5{{comparison of distinct pointer types ('__{{global|constant}} int *' and 'int *')}} 260#endif 261#endif 262 263 b = var_cmp >= arg_gen; 264#ifdef CONSTANT 265#if !__OPENCL_CPP_VERSION__ 266// expected-error@-3{{comparison between ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 267#else 268// expected-error@-5{{comparison of distinct pointer types ('__constant int *' and '__generic int *')}} 269#endif 270#endif 271 272 AS int *var_sub; 273 b = var_sub - arg_glob; 274#ifdef CONSTANT 275// expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 276#endif 277 278 b = var_sub - arg_loc; 279#ifndef GENERIC 280// expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 281#endif 282 283 b = var_sub - arg_const; 284#ifndef CONSTANT 285// expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 286#endif 287 288 b = var_sub - arg_priv; 289#ifndef GENERIC 290// expected-error-re@-2{{arithmetic operation with operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 291#endif 292 293 b = var_sub - arg_gen; 294#ifdef CONSTANT 295// expected-error@-2{{arithmetic operation with operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 296#endif 297 298 f_glob(var_sub); 299#ifndef GLOBAL 300#if !__OPENCL_CPP_VERSION__ 301// expected-error-re@-3{{passing '__{{constant|generic}} int *' to parameter of type '__global int *' changes address space of pointer}} 302#else 303// expected-error@-5{{no matching function for call to 'f_glob'}} 304#endif 305#endif 306 307 f_loc(var_sub); 308#if !__OPENCL_CPP_VERSION__ 309// expected-error-re@-2{{passing '__{{global|constant|generic}} int *' to parameter of type '__local int *' changes address space of pointer}} 310#else 311// expected-error@-4{{no matching function for call to 'f_loc'}} 312#endif 313 314 f_const(var_sub); 315#ifndef CONSTANT 316#if !__OPENCL_CPP_VERSION__ 317// expected-error-re@-3{{passing '__{{global|generic}} int *' to parameter of type '__constant int *' changes address space of pointer}} 318#else 319// expected-error@-5{{no matching function for call to 'f_const'}} 320#endif 321#endif 322 323 f_priv(var_sub); 324#if !__OPENCL_CPP_VERSION__ 325// expected-error-re@-2{{passing '__{{global|constant|generic}} int *' to parameter of type 'int *' changes address space of pointer}} 326#else 327// expected-error@-4{{no matching function for call to 'f_priv'}} 328#endif 329 330 f_gen(var_sub); 331#ifdef CONSTANT 332#if !__OPENCL_CPP_VERSION__ 333// expected-error@-3{{passing '__constant int *' to parameter of type '__generic int *' changes address space of pointer}} 334#else 335// expected-error@-5{{no matching function for call to 'f_gen'}} 336#endif 337#endif 338} 339 340void test_ternary() { 341 AS int *var_cond; 342 __generic int *var_gen; 343 __global int *var_glob; 344 var_gen = 0 ? var_cond : var_glob; 345#ifdef CONSTANT 346#if !__OPENCL_CPP_VERSION__ 347// expected-error@-3{{conditional operator with the second and third operands of type ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}} 348#else 349// expected-error@-5{{incompatible operand types ('__constant int *' and '__global int *')}} 350#endif 351#endif 352 353 __local int *var_loc; 354 var_gen = 0 ? var_cond : var_loc; 355#ifndef GENERIC 356#if !__OPENCL_CPP_VERSION__ 357// expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}} 358#else 359// expected-error-re@-5{{incompatible operand types ('__{{global|constant}} int *' and '__local int *')}} 360#endif 361#endif 362 363 __constant int *var_const; 364 var_cond = 0 ? var_cond : var_const; 365#ifndef CONSTANT 366#if !__OPENCL_CPP_VERSION__ 367// expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}} 368#else 369// expected-error-re@-5{{incompatible operand types ('__{{global|generic}} int *' and '__constant int *')}} 370#endif 371#endif 372 373 __private int *var_priv; 374 var_gen = 0 ? var_cond : var_priv; 375#ifndef GENERIC 376#if !__OPENCL_CPP_VERSION__ 377// expected-error-re@-3{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}} 378#else 379// expected-error-re@-5{{incompatible operand types ('__{{global|constant}} int *' and 'int *')}} 380#endif 381#endif 382 383 var_gen = 0 ? var_cond : var_gen; 384#ifdef CONSTANT 385#if !__OPENCL_CPP_VERSION__ 386// expected-error@-3{{conditional operator with the second and third operands of type ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}} 387#else 388// expected-error@-5{{incompatible operand types ('__constant int *' and '__generic int *')}} 389#endif 390#endif 391 392 void *var_void_gen; 393 __global char *var_glob_ch; 394 var_void_gen = 0 ? var_cond : var_glob_ch; 395#if __OPENCL_CPP_VERSION__ 396// expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__global char *')}} 397#else 398#ifdef CONSTANT 399// expected-error@-5{{conditional operator with the second and third operands of type ('__constant int *' and '__global char *') which are pointers to non-overlapping address spaces}} 400#else 401// expected-warning-re@-7{{pointer type mismatch ('__{{global|generic}} int *' and '__global char *')}} 402#endif 403#endif 404 405 __local char *var_loc_ch; 406 var_void_gen = 0 ? var_cond : var_loc_ch; 407#if __OPENCL_CPP_VERSION__ 408// expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__local char *')}} 409#else 410#ifndef GENERIC 411// expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and '__local char *') which are pointers to non-overlapping address spaces}} 412#else 413// expected-warning@-7{{pointer type mismatch ('__generic int *' and '__local char *')}} 414#endif 415#endif 416 417 __constant void *var_void_const; 418 __constant char *var_const_ch; 419 var_void_const = 0 ? var_cond : var_const_ch; 420#if __OPENCL_CPP_VERSION__ 421// expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__constant char *')}} 422#else 423#ifndef CONSTANT 424// expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|generic}} int *' and '__constant char *') which are pointers to non-overlapping address spaces}} 425#else 426// expected-warning@-7{{pointer type mismatch ('__constant int *' and '__constant char *')}} 427#endif 428#endif 429 430 __private char *var_priv_ch; 431 var_void_gen = 0 ? var_cond : var_priv_ch; 432#if __OPENCL_CPP_VERSION__ 433// expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and 'char *')}} 434#else 435#ifndef GENERIC 436// expected-error-re@-5{{conditional operator with the second and third operands of type ('__{{global|constant}} int *' and 'char *') which are pointers to non-overlapping address spaces}} 437#else 438// expected-warning@-7{{pointer type mismatch ('__generic int *' and 'char *')}} 439#endif 440#endif 441 442 __generic char *var_gen_ch; 443 var_void_gen = 0 ? var_cond : var_gen_ch; 444#if __OPENCL_CPP_VERSION__ 445// expected-error-re@-2{{incompatible operand types ('__{{constant|global|generic}} int *' and '__generic char *')}} 446#else 447#ifdef CONSTANT 448// expected-error@-5{{conditional operator with the second and third operands of type ('__constant int *' and '__generic char *') which are pointers to non-overlapping address spaces}} 449#else 450// expected-warning-re@-7{{pointer type mismatch ('__{{global|generic}} int *' and '__generic char *')}} 451#endif 452#endif 453} 454 455void test_pointer_chains() { 456 AS int *AS *var_as_as_int; 457 AS int *AS_COMP *var_asc_as_int; 458 AS_INCOMP int *AS_COMP *var_asc_asn_int; 459 AS_COMP int *AS_COMP *var_asc_asc_int; 460 461 // Case 1: 462 // * address spaces of corresponded most outer pointees overlaps, their canonical types are equal 463 // * CVR, address spaces and canonical types of the rest of pointees are equivalent. 464 var_as_as_int = 0 ? var_as_as_int : var_asc_as_int; 465#if __OPENCL_CPP_VERSION__ 466#ifdef GENERIC 467// expected-error@-3{{incompatible operand types ('__generic int *__generic *' and '__generic int *__local *')}} 468#endif 469#endif 470 // Case 2: Corresponded inner pointees has non-overlapping address spaces. 471 var_as_as_int = 0 ? var_as_as_int : var_asc_asn_int; 472#if !__OPENCL_CPP_VERSION__ 473// expected-warning-re@-2{{pointer type mismatch ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(constant|local|global)}} *')}} 474#else 475// expected-error-re@-4{{incompatible operand types ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(constant|local|global)}} *')}} 476#endif 477 478 // Case 3: Corresponded inner pointees has overlapping but not equivalent address spaces. 479#ifdef GENERIC 480 var_as_as_int = 0 ? var_as_as_int : var_asc_asc_int; 481#if !__OPENCL_CPP_VERSION__ 482// expected-warning-re@-2{{pointer type mismatch ('__{{(generic|global|constant)}} int *__{{(generic|global|constant)}} *' and '__{{(local|global|constant)}} int *__{{(local|global|constant)}} *')}} 483#else 484// expected-error-re@-4{{incompatible operand types ('__{{generic|global|constant}} int *__{{generic|global|constant}} *' and '__{{local|global|constant}} int *__{{local|global|constant}} *')}} 485#endif 486#endif 487} 488