blob: 26389d24fce86cd6176f976149e1857b692d69f3 [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;
Sven van Haastregtd1f30022018-09-27 13:20:29 +00008 private int *priv;
9 global float *glob_wrong_ty;
Yaxun Liuf7449a12016-05-20 19:54:38 +000010 typedef constant int const_int_ty;
11 const_int_ty *con_typedef;
12
13 glob = to_global(glob, loc);
14#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulovaae2e86f2018-09-24 14:21:56 +000015 // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000016 // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000017#else
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000018 // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000019#endif
20
21 int x;
22 glob = to_global(x);
23#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000024 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000025#else
26 // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
27#endif
28
29 glob = to_global(con);
30#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000031 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000032#else
33 // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
34#endif
35
36 glob = to_global(con_typedef);
37#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000038 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000039#else
40 // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
41#endif
42
43 loc = to_global(glob);
44#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +000045 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +000046#else
47 // expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}}
Sven van Haastregt1076cc22018-09-20 10:07:27 +000048 // 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 +000049#endif
50
Sven van Haastregtd1f30022018-09-27 13:20:29 +000051 loc = to_private(glob);
52#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
53 // expected-error@-2{{implicit declaration of function 'to_private' is invalid in OpenCL}}
54 // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
55#else
56 // expected-error@-5{{assigning 'int *' to '__local int *' changes address space of pointer}}
57 // expected-warning@-6{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
58#endif
59
60 loc = to_local(glob);
61#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
62 // expected-error@-2{{implicit declaration of function 'to_local' is invalid in OpenCL}}
63 // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
64 // expected-note@-4{{did you mean 'to_global'}}
65 // expected-note@13{{'to_global' declared here}}
66#else
67 // expected-warning@-7{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
68#endif
69
70 priv = to_global(glob);
71#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
72 // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
73#else
74 // expected-error@-4{{assigning '__global int *' to 'int *' changes address space of pointer}}
75 // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
76#endif
77
78 priv = to_private(glob);
79#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
80 // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
81#else
82 // expected-warning@-4{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
83#endif
84
85
86 priv = to_local(glob);
87#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
88 // expected-warning@-2{{incompatible integer to pointer conversion assigning to 'int *' from 'int'}}
89#else
90 // expected-error@-4{{assigning '__local int *' to 'int *' changes address space of pointer}}
91 // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
92#endif
93
94 glob = to_global(glob);
95#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
96 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
97#else
98 // expected-warning@-4{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
99#endif
100
101 glob = to_private(glob);
102#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
103 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
104#else
105 // expected-error@-4{{assigning 'int *' to '__global int *' changes address space of pointer}}
106 // expected-warning@-5{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
107#endif
108
109 glob = to_local(glob);
110#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
111 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
112#else
113 // expected-error@-4{{assigning '__local int *' to '__global int *' changes address space of pointer}}
114 // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
115#endif
116
Yaxun Liuf7449a12016-05-20 19:54:38 +0000117 global char *glob_c = to_global(loc);
118#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
Anastasia Stulova7f8d6dc2016-07-04 16:07:18 +0000119 // expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}}
Yaxun Liuf7449a12016-05-20 19:54:38 +0000120#else
121 // expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}}
Sven van Haastregt1076cc22018-09-20 10:07:27 +0000122 // 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 +0000123#endif
124
Sven van Haastregtd1f30022018-09-27 13:20:29 +0000125 glob_wrong_ty = to_global(glob);
126#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
127 // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global float *' from 'int'}}
128#else
129 // expected-warning@-4{{incompatible pointer types assigning to '__global float *' from '__global int *'}}
130 // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
131#endif
132
Yaxun Liuf7449a12016-05-20 19:54:38 +0000133}