blob: fb21a1573b0cb9602cf681d2275bcf71a9f6488e [file] [log] [blame]
Yaxun Liuf7449a12016-05-20 19:54:38 +00001// RUN: %clang_cc1 -verify -fsyntax-only %s
Sven van Haastregt1076cc22018-09-20 10:07:27 +00002// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
Yaxun Liuf7449a12016-05-20 19:54:38 +00003
4void test(void) {
5 global int *glob;
6 local int *loc;
7 constant int *con;
8 typedef constant int const_int_ty;
9 const_int_ty *con_typedef;
10
11 glob = to_global(glob, loc);
12#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulovaae2e86f2018-09-24 14:21:56 +000013 // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000014 // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000015#else
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000016 // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000017#endif
18
19 int x;
20 glob = to_global(x);
21#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000022 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000023#else
24 // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
25#endif
26
27 glob = to_global(con);
28#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000029 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000030#else
31 // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
32#endif
33
34 glob = to_global(con_typedef);
35#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000036 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000037#else
38 // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
39#endif
40
41 loc = to_global(glob);
42#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000043 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000044#else
45 // expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}}
Sven van Haastregt1076cc22018-09-20 10:07:27 +000046 // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000047#endif
48
49 global char *glob_c = to_global(loc);
50#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000051 // expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000052#else
53 // expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}}
Sven van Haastregt1076cc22018-09-20 10:07:27 +000054 // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000055#endif
56
57}