address-spaces-conversions-cl2.0.cl 21 KB

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