1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4 // expected-no-diagnostics
5
6 #ifndef HEADER
7 #define HEADER
8
foo()9 void foo() {}
10
11 struct S {
SS12 S(): a(0) {}
SS13 S(int v) : a(v) {}
14 int a;
15 typedef int type;
16 };
17
18 template <typename T>
19 class S7 : public T {
20 protected:
21 T a;
S7()22 S7() : a(0) {}
23
24 public:
S7(typename T::type v)25 S7(typename T::type v) : a(v) {
26 #pragma omp target parallel for simd private(a) private(this->a) private(T::a)
27 for (int k = 0; k < a.a; ++k)
28 ++this->a.a;
29 }
operator =(S7 & s)30 S7 &operator=(S7 &s) {
31 #pragma omp target parallel for simd private(a) private(this->a)
32 for (int k = 0; k < s.a.a; ++k)
33 ++s.a.a;
34 return *this;
35 }
36 };
37
38 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(this->S::a)
39 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(T::a)
40 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a)
41
42 class S8 : public S7<S> {
S8()43 S8() {}
44
45 public:
S8(int v)46 S8(int v) : S7<S>(v){
47 #pragma omp target parallel for simd private(a) private(this->a) private(S7<S>::a)
48 for (int k = 0; k < a.a; ++k)
49 ++this->a.a;
50 }
operator =(S8 & s)51 S8 &operator=(S8 &s) {
52 #pragma omp target parallel for simd private(a) private(this->a)
53 for (int k = 0; k < s.a.a; ++k)
54 ++s.a.a;
55 return *this;
56 }
57 };
58
59 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(this->S7<S>::a)
60 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a)
61
62 template <class T, int N>
tmain(T argc,T * argv)63 T tmain(T argc, T *argv) {
64 T b = argc, c, d, e, f, h;
65 T arr[N][10], arr1[N];
66 T i, j;
67 T s;
68 static T a;
69 // CHECK: static T a;
70 static T g;
71 const T clen = 5;
72 // CHECK: T clen = 5;
73 #pragma omp threadprivate(g)
74 #pragma omp target parallel for simd schedule(dynamic) default(none) linear(a)
75 // CHECK: #pragma omp target parallel for simd schedule(dynamic) default(none) linear(a)
76 for (T i = 0; i < 2; ++i)
77 a = 2;
78 // CHECK-NEXT: for (T i = 0; i < 2; ++i)
79 // CHECK-NEXT: a = 2;
80 #pragma omp target parallel for simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h)
81 for (int i = 0; i < 2; ++i)
82 for (int j = 0; j < 2; ++j)
83 for (int j = 0; j < 2; ++j)
84 for (int j = 0; j < 2; ++j)
85 for (int j = 0; j < 2; ++j)
86 foo();
87 // CHECK-NEXT: #pragma omp target parallel for simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h)
88 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
89 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
90 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
91 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
92 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
93 // CHECK-NEXT: foo();
94
95 #pragma omp target parallel for simd default(none), private(argc,b) firstprivate(argv) shared (d) if(parallel:argc > 0) num_threads(N) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:N][0:10])
96 for (T i = 0; i < 2; ++i) {}
97 // CHECK: #pragma omp target parallel for simd default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(N) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:N][0:10])
98 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
99 // CHECK-NEXT: }
100
101 #pragma omp target parallel for simd if(N) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:N][:argc]) reduction(&& : h)
102 for (T i = 0; i < 2; ++i) {}
103 // CHECK: #pragma omp target parallel for simd if(N) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:N][:argc]) reduction(&&: h)
104 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
105 // CHECK-NEXT: }
106
107 #pragma omp target parallel for simd if(target:argc > 0)
108 for (T i = 0; i < 2; ++i) {}
109 // CHECK: #pragma omp target parallel for simd if(target: argc > 0)
110 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
111 // CHECK-NEXT: }
112
113 #pragma omp target parallel for simd if(parallel:argc > 0)
114 for (T i = 0; i < 2; ++i) {}
115 // CHECK: #pragma omp target parallel for simd if(parallel: argc > 0)
116 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
117 // CHECK-NEXT: }
118
119 #pragma omp target parallel for simd if(N)
120 for (T i = 0; i < 2; ++i) {}
121 // CHECK: #pragma omp target parallel for simd if(N)
122 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
123 // CHECK-NEXT: }
124
125 #pragma omp target parallel for simd map(i)
126 for (T i = 0; i < 2; ++i) {}
127 // CHECK: #pragma omp target parallel for simd map(tofrom: i)
128 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
129 // CHECK-NEXT: }
130
131 #pragma omp target parallel for simd map(arr1[0:10], i)
132 for (T i = 0; i < 2; ++i) {}
133 // CHECK: #pragma omp target parallel for simd map(tofrom: arr1[0:10],i)
134 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
135 // CHECK-NEXT: }
136
137 #pragma omp target parallel for simd map(to: i) map(from: j)
138 for (T i = 0; i < 2; ++i) {}
139 // CHECK: #pragma omp target parallel for simd map(to: i) map(from: j)
140 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
141 // CHECK-NEXT: }
142
143 #pragma omp target parallel for simd map(always,alloc: i)
144 for (T i = 0; i < 2; ++i) {}
145 // CHECK: #pragma omp target parallel for simd map(always,alloc: i)
146 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
147 // CHECK-NEXT: }
148
149 #pragma omp target parallel for simd nowait
150 for (T i = 0; i < 2; ++i) {}
151 // CHECK: #pragma omp target parallel for simd nowait
152 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
153 // CHECK-NEXT: }
154
155 #pragma omp target parallel for simd depend(in : argc, arr[i:argc], arr1[:])
156 for (T i = 0; i < 2; ++i) {}
157 // CHECK: #pragma omp target parallel for simd depend(in : argc,arr[i:argc],arr1[:])
158 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
159 // CHECK-NEXT: }
160
161 #pragma omp target parallel for simd defaultmap(tofrom: scalar)
162 for (T i = 0; i < 2; ++i) {}
163 // CHECK: #pragma omp target parallel for simd defaultmap(tofrom: scalar)
164 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
165 // CHECK-NEXT: }
166
167 #pragma omp target parallel for simd safelen(clen-1)
168 for (T i = 0; i < 2; ++i) {}
169 // CHECK: #pragma omp target parallel for simd safelen(clen - 1)
170 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
171 // CHECK-NEXT: }
172
173 #pragma omp target parallel for simd simdlen(clen-1)
174 for (T i = 0; i < 2; ++i) {}
175 // CHECK: #pragma omp target parallel for simd simdlen(clen - 1)
176 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
177 // CHECK-NEXT: }
178
179 #pragma omp target parallel for simd aligned(arr1:N-1)
180 for (T i = 0; i < N; ++i) {}
181 // CHECK: #pragma omp target parallel for simd aligned(arr1: N - 1)
182 // CHECK-NEXT: for (T i = 0; i < N; ++i) {
183 // CHECK-NEXT: }
184
185 return T();
186 }
187
main(int argc,char ** argv)188 int main(int argc, char **argv) {
189 int b = argc, c, d, e, f, h;
190 int arr[5][10], arr1[5];
191 int i, j;
192 int s;
193 static int a;
194 // CHECK: static int a;
195 const int clen = 5;
196 // CHECK: int clen = 5;
197 static float g;
198 #pragma omp threadprivate(g)
199 #pragma omp target parallel for simd schedule(guided, argc) default(none) linear(a)
200 // CHECK: #pragma omp target parallel for simd schedule(guided, argc) default(none) linear(a)
201 for (int i = 0; i < 2; ++i)
202 a = 2;
203 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
204 // CHECK-NEXT: a = 2;
205
206 #pragma omp target parallel for simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (target: argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a:-5)
207 for (int i = 0; i < 10; ++i)
208 for (int j = 0; j < 10; ++j)
209 foo();
210 // CHECK: #pragma omp target parallel for simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered if(target: argc) num_threads(a) default(shared) shared(e) reduction(+: h) linear(a: -5)
211 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
212 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
213 // CHECK-NEXT: foo();
214
215 #pragma omp target parallel for simd default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(5) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:5][0:10])
216 for (int i = 0; i < 2; ++i) {}
217 // CHECK: #pragma omp target parallel for simd default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
218 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
219 // CHECK-NEXT: }
220
221 #pragma omp target parallel for simd if (5) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:5][:argc]) reduction(&& : h)
222 for (int i = 0; i < 2; ++i) {}
223 // CHECK: #pragma omp target parallel for simd if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: h)
224 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
225 // CHECK-NEXT: }
226
227 #pragma omp target parallel for simd if (target:argc > 0)
228 for (int i = 0; i < 2; ++i) {}
229 // CHECK: #pragma omp target parallel for simd if(target: argc > 0)
230 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
231 // CHECK-NEXT: }
232
233 #pragma omp target parallel for simd if (parallel:argc > 0)
234 for (int i = 0; i < 2; ++i) {}
235 // CHECK: #pragma omp target parallel for simd if(parallel: argc > 0)
236 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
237 // CHECK-NEXT: }
238
239 #pragma omp target parallel for simd if (5)
240 for (int i = 0; i < 2; ++i) {}
241 // CHECK: #pragma omp target parallel for simd if(5)
242 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
243 // CHECK-NEXT: }
244
245 #pragma omp target parallel for simd map(i)
246 for (int i = 0; i < 2; ++i) {}
247 // CHECK: #pragma omp target parallel for simd map(tofrom: i)
248 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
249 // CHECK-NEXT: }
250
251 #pragma omp target parallel for simd map(arr1[0:10], i)
252 for (int i = 0; i < 2; ++i) {}
253 // CHECK: #pragma omp target parallel for simd map(tofrom: arr1[0:10],i)
254 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
255 // CHECK-NEXT: }
256
257 #pragma omp target parallel for simd map(to: i) map(from: j)
258 for (int i = 0; i < 2; ++i) {}
259 // CHECK: #pragma omp target parallel for simd map(to: i) map(from: j)
260 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
261 // CHECK-NEXT: }
262
263 #pragma omp target parallel for simd map(always,alloc: i)
264 for (int i = 0; i < 2; ++i) {}
265 // CHECK: #pragma omp target parallel for simd map(always,alloc: i)
266 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
267 // CHECK-NEXT: }
268
269 #pragma omp target parallel for simd nowait
270 for (int i = 0; i < 2; ++i) {}
271 // CHECK: #pragma omp target parallel for simd nowait
272 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
273 // CHECK-NEXT: }
274
275 #pragma omp target parallel for simd depend(in : argc, arr[i:argc], arr1[:])
276 for (int i = 0; i < 2; ++i) {}
277 // CHECK: #pragma omp target parallel for simd depend(in : argc,arr[i:argc],arr1[:])
278 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
279 // CHECK-NEXT: }
280
281 #pragma omp target parallel for simd defaultmap(tofrom: scalar)
282 for (int i = 0; i < 2; ++i) {}
283 // CHECK: #pragma omp target parallel for simd defaultmap(tofrom: scalar)
284 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
285 // CHECK-NEXT: }
286
287 #pragma omp target parallel for simd safelen(clen-1)
288 for (int i = 0; i < 2; ++i) {}
289 // CHECK: #pragma omp target parallel for simd safelen(clen - 1)
290 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
291 // CHECK-NEXT: }
292
293 #pragma omp target parallel for simd simdlen(clen-1)
294 for (int i = 0; i < 2; ++i) {}
295 // CHECK: #pragma omp target parallel for simd simdlen(clen - 1)
296 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
297 // CHECK-NEXT: }
298
299 #pragma omp target parallel for simd aligned(arr1:4)
300 for (int i = 0; i < 2; ++i) {}
301 // CHECK: #pragma omp target parallel for simd aligned(arr1: 4)
302 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
303 // CHECK-NEXT: }
304
305 return (tmain<int, 5>(argc, &argc));
306 }
307
308 #endif
309