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
5/* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
6*  different address spaces, mainly described in Sections 6.5.5 and 6.5.6.
7*
8*  It adds notion of overlapping address spaces. The main differention is that
9*  an unnamed address space is added, called '__generic'. Pointers to the
10*  generic address space can be interchangabley used with pointers to any
11*  other address space except for __constant address space (Section 6.5.5).
12*
13*  Based on this there are 3 sets of tests: __generic, named (__global in this
14*  case), and __constant, that should cover all program paths for CL address
15*  space conversions used in initialisations, assignments, casts, comparisons
16*  and arithmetic operations.
17*/
18
19#ifdef GENERIC
20#define AS generic
21#endif
22
23#ifdef GLOBAL
24#define AS global
25#endif
26
27#ifdef CONSTANT
28#define AS constant
29#endif
30
31void f_glob(global int *arg_glob) {}
32#ifndef GLOBAL
33// expected-note@-2{{passing argument to parameter 'arg_glob' here}}
34#endif
35
36void f_loc(local int *arg_loc) {
37} // expected-note@-1{{passing argument to parameter 'arg_loc' here}}
38
39void f_const(constant int *arg_const) {}
40#ifndef CONSTANT
41// expected-note@-2{{passing argument to parameter 'arg_const' here}}
42#endif
43
44void f_priv(private int *arg_priv) {
45} // expected-note@-1{{passing argument to parameter 'arg_priv' here}}
46
47void f_gen(generic int *arg_gen) {}
48#ifdef CONSTANT
49// expected-note@-2{{passing argument to parameter 'arg_gen' here}}
50#endif
51
52void test_conversion(global int *arg_glob, local int *arg_loc,
53                     constant int *arg_const, private int *arg_priv,
54                     generic int *arg_gen) {
55
56  AS int *var_init1 = arg_glob;
57#ifdef CONSTANT
58// expected-error@-2{{initializing '__constant int *' with an expression of type '__global int *' changes address space of pointer}}
59#endif
60
61  AS int *var_init2 = arg_loc;
62#ifndef GENERIC
63// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__local int *' changes address space of pointer}}
64#endif
65
66  AS int *var_init3 = arg_const;
67#ifndef CONSTANT
68// expected-error-re@-2{{initializing '__{{global|generic}} int *' with an expression of type '__constant int *' changes address space of pointer}}
69#endif
70
71  AS int *var_init4 = arg_priv;
72#ifndef GENERIC
73// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type 'int *' changes address space of pointer}}
74#endif
75
76  AS int *var_init5 = arg_gen;
77#ifndef GENERIC
78// expected-error-re@-2{{initializing '__{{global|constant}} int *' with an expression of type '__generic int *' changes address space of pointer}}
79#endif
80
81  AS int *var_cast1 = (AS int *)arg_glob;
82#ifdef CONSTANT
83// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}}
84#endif
85
86  AS int *var_cast2 = (AS int *)arg_loc;
87#ifndef GENERIC
88// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}}
89#endif
90
91  AS int *var_cast3 = (AS int *)arg_const;
92#ifndef CONSTANT
93// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}}
94#endif
95
96  AS int *var_cast4 = (AS int *)arg_priv;
97#ifndef GENERIC
98// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}}
99#endif
100
101  AS int *var_cast5 = (AS int *)arg_gen;
102#ifdef CONSTANT
103// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}}
104#endif
105
106  AS int *var_impl;
107  var_impl = arg_glob;
108#ifdef CONSTANT
109// expected-error@-2{{assigning '__global int *' to '__constant int *' changes address space of pointer}}
110#endif
111
112  var_impl = arg_loc;
113#ifndef GENERIC
114// expected-error-re@-2{{assigning '__local int *' to '__{{global|constant}} int *' changes address space of pointer}}
115#endif
116
117  var_impl = arg_const;
118#ifndef CONSTANT
119// expected-error-re@-2{{assigning '__constant int *' to '__{{global|generic}} int *' changes address space of pointer}}
120#endif
121
122  var_impl = arg_priv;
123#ifndef GENERIC
124// expected-error-re@-2{{assigning 'int *' to '__{{global|constant}} int *' changes address space of pointer}}
125#endif
126
127  var_impl = arg_gen;
128#ifndef GENERIC
129// expected-error-re@-2{{assigning '__generic int *' to '__{{global|constant}} int *' changes address space of pointer}}
130#endif
131
132  var_cast1 = (AS int *)arg_glob;
133#ifdef CONSTANT
134// expected-error@-2{{casting '__global int *' to type '__constant int *' changes address space of pointer}}
135#endif
136
137  var_cast2 = (AS int *)arg_loc;
138#ifndef GENERIC
139// expected-error-re@-2{{casting '__local int *' to type '__{{global|constant}} int *' changes address space of pointer}}
140#endif
141
142  var_cast3 = (AS int *)arg_const;
143#ifndef CONSTANT
144// expected-error-re@-2{{casting '__constant int *' to type '__{{global|generic}} int *' changes address space of pointer}}
145#endif
146
147  var_cast4 = (AS int *)arg_priv;
148#ifndef GENERIC
149// expected-error-re@-2{{casting 'int *' to type '__{{global|constant}} int *' changes address space of pointer}}
150#endif
151
152  var_cast5 = (AS int *)arg_gen;
153#ifdef CONSTANT
154// expected-error@-2{{casting '__generic int *' to type '__constant int *' changes address space of pointer}}
155#endif
156
157  AS int *var_cmp;
158  int b = var_cmp != arg_glob;
159#ifdef CONSTANT
160// expected-error@-2{{comparison between  ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}}
161#endif
162
163  b = var_cmp != arg_loc;
164#ifndef GENERIC
165// expected-error-re@-2{{comparison between  ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}}
166#endif
167
168  b = var_cmp == arg_const;
169#ifndef CONSTANT
170// expected-error-re@-2{{comparison between  ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}}
171#endif
172
173  b = var_cmp <= arg_priv;
174#ifndef GENERIC
175// expected-error-re@-2{{comparison between  ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}}
176#endif
177
178  b = var_cmp >= arg_gen;
179#ifdef CONSTANT
180// expected-error@-2{{comparison between  ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}}
181#endif
182
183  AS int *var_sub;
184  b = var_sub - arg_glob;
185#ifdef CONSTANT
186// expected-error@-2{{arithmetic operation with operands of type  ('__constant int *' and '__global int *') which are pointers to non-overlapping address spaces}}
187#endif
188
189  b = var_sub - arg_loc;
190#ifndef GENERIC
191// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|constant}} int *' and '__local int *') which are pointers to non-overlapping address spaces}}
192#endif
193
194  b = var_sub - arg_const;
195#ifndef CONSTANT
196// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|generic}} int *' and '__constant int *') which are pointers to non-overlapping address spaces}}
197#endif
198
199  b = var_sub - arg_priv;
200#ifndef GENERIC
201// expected-error-re@-2{{arithmetic operation with operands of type  ('__{{global|constant}} int *' and 'int *') which are pointers to non-overlapping address spaces}}
202#endif
203
204  b = var_sub - arg_gen;
205#ifdef CONSTANT
206// expected-error@-2{{arithmetic operation with operands of type  ('__constant int *' and '__generic int *') which are pointers to non-overlapping address spaces}}
207#endif
208
209  f_glob(var_sub);
210#ifndef GLOBAL
211// expected-error-re@-2{{passing '__{{constant|generic}} int *' to parameter of type '__global int *' changes address space of pointer}}
212#endif
213
214  f_loc(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type '__local int *' changes address space of pointer}}
215
216  f_const(var_sub);
217#ifndef CONSTANT
218// expected-error-re@-2{{passing '__{{global|generic}} int *' to parameter of type '__constant int *' changes address space of pointer}}
219#endif
220
221  f_priv(var_sub); // expected-error-re{{passing '__{{global|constant|generic}} int *' to parameter of type 'int *' changes address space of pointer}}
222
223  f_gen(var_sub);
224#ifdef CONSTANT
225// expected-error@-2{{passing '__constant int *' to parameter of type '__generic int *' changes address space of pointer}}
226#endif
227}
228