xref: /llvm-project/clang/test/SemaOpenCL/to_addr_builtin.cl (revision a9d68a5524dea113cace5983697786599cbdce9a)
1// RUN: %clang_cc1 -verify -fsyntax-only %s
2// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL2.0 %s
3// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 -cl-ext=-all %s
4// RUN: %clang_cc1 -Wconversion -verify -fsyntax-only -cl-std=CL3.0 %s
5
6void test(void) {
7  global int *glob;
8  local int *loc;
9  constant int *con;
10  private int *priv;
11  global float *glob_wrong_ty;
12  typedef constant int const_int_ty;
13  const_int_ty *con_typedef;
14
15  glob = to_global(glob, loc);
16#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
17  // expected-error@-2{{use of undeclared identifier 'to_global'}}
18#else
19  // expected-error@-4{{too many arguments to function call, expected 1, have 2}}
20#endif
21
22  int x;
23  glob = to_global(x);
24#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
25  // expected-error@-2{{use of undeclared identifier 'to_global'}}
26#else
27  // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
28#endif
29
30  glob = to_global(con);
31#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
32  // expected-error@-2{{use of undeclared identifier 'to_global'}}
33#else
34  // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
35#endif
36
37  glob = to_global(con_typedef);
38#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
39  // expected-error@-2{{use of undeclared identifier 'to_global'}}
40#else
41  // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
42#endif
43
44  loc = to_global(glob);
45#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
46  // expected-error@-2{{use of undeclared identifier 'to_global'}}
47#else
48  // expected-error@-4{{assigning '__global int *' to '__local int *__private' changes address space of pointer}}
49  // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
50#endif
51
52  loc = to_private(glob);
53#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
54  // expected-error@-2{{use of undeclared identifier 'to_private'}}
55#else
56  // expected-error@-4{{assigning '__private int *' to '__local int *__private' changes address space of pointer}}
57  // expected-warning@-5{{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) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
62  // expected-error@-2{{use of undeclared identifier 'to_local'}}
63#else
64  // expected-warning@-4{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
65#endif
66
67  priv = to_global(glob);
68#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
69  // expected-error@-2{{use of undeclared identifier 'to_global'}}
70#else
71  // expected-error@-4{{assigning '__global int *' to '__private int *__private' changes address space of pointer}}
72  // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
73#endif
74
75  priv = to_private(glob);
76#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
77  // expected-error@-2{{use of undeclared identifier 'to_private'}}
78#else
79  // expected-warning@-4{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
80#endif
81
82
83  priv = to_local(glob);
84#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
85  // expected-error@-2{{use of undeclared identifier 'to_local'}}
86#else
87  // expected-error@-4{{assigning '__local int *' to '__private int *__private' changes address space of pointer}}
88  // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
89#endif
90
91  glob = to_global(glob);
92#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
93  // expected-error@-2{{use of undeclared identifier 'to_global'}}
94#else
95  // expected-warning@-4{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
96#endif
97
98  glob = to_private(glob);
99#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
100  // expected-error@-2{{use of undeclared identifier 'to_private'}}
101#else
102  // expected-error@-4{{assigning '__private int *' to '__global int *__private' changes address space of pointer}}
103  // expected-warning@-5{{passing non-generic address space pointer to to_private may cause dynamic conversion affecting performance}}
104#endif
105
106  glob = to_local(glob);
107#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
108  // expected-error@-2{{use of undeclared identifier 'to_local'}}
109#else
110  // expected-error@-4{{assigning '__local int *' to '__global int *__private' changes address space of pointer}}
111  // expected-warning@-5{{passing non-generic address space pointer to to_local may cause dynamic conversion affecting performance}}
112#endif
113
114  global char *glob_c = to_global(loc);
115#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
116  // expected-error@-2{{use of undeclared identifier 'to_global'}}
117#else
118  // expected-warning@-4{{incompatible pointer types initializing '__global char *__private' with an expression of type '__global int *'}}
119  // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
120#endif
121
122  glob_wrong_ty = to_global(glob);
123#if (__OPENCL_C_VERSION__ < CL_VERSION_2_0) || (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && !defined(__opencl_c_generic_address_space))
124  // expected-error@-2{{use of undeclared identifier 'to_global'}}
125#else
126  // expected-warning@-4{{incompatible pointer types assigning to '__global float *__private' from '__global int *'}}
127  // expected-warning@-5{{passing non-generic address space pointer to to_global may cause dynamic conversion affecting performance}}
128#endif
129
130}
131