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 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 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 private(this->a) private(this->a) private(this->S::a)
39 // CHECK: #pragma omp target parallel for private(this->a) private(this->a) private(T::a)
40 // CHECK: #pragma omp target parallel for 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 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 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 private(this->a) private(this->a) private(this->S7<S>::a)
60 // CHECK: #pragma omp target parallel for 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 #pragma omp threadprivate(g)
72 #pragma omp target parallel for schedule(dynamic) default(none) linear(a)
73 // CHECK: #pragma omp target parallel for schedule(dynamic) default(none) linear(a)
74 for (int i = 0; i < 2; ++i)
75 a = 2;
76 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
77 // CHECK-NEXT: a = 2;
78 #pragma omp target parallel for 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)
79 for (int i = 0; i < 2; ++i)
80 for (int j = 0; j < 2; ++j)
81 for (int j = 0; j < 2; ++j)
82 for (int j = 0; j < 2; ++j)
83 for (int j = 0; j < 2; ++j)
84 for (int i = 0; i < 2; ++i)
85 for (int j = 0; j < 2; ++j)
86 for (int j = 0; j < 2; ++j)
87 for (int j = 0; j < 2; ++j)
88 for (int j = 0; j < 2; ++j)
89 foo();
90 // CHECK-NEXT: #pragma omp target parallel for 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)
91 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
92 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
93 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
94 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
95 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
96 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
97 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
98 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
99 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
100 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
101 // CHECK-NEXT: foo();
102 #pragma omp target parallel for 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])
103 for (int i = 0; i < 2; ++i) {}
104 // CHECK-NEXT: #pragma omp target parallel for 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])
105 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
106 // CHECK-NEXT: }
107 #pragma omp target parallel for if (N) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:N][:argc]) reduction(&& : h)
108 // CHECK-NEXT: #pragma omp target parallel for if(N) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:N][:argc]) reduction(&&: h)
109 for (int i = 0; i < 2; ++i) {}
110 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
111 // CHECK-NEXT: }
112 #pragma omp target parallel for if (target:argc > 0)
113 // CHECK-NEXT: #pragma omp target parallel for if(target: argc > 0)
114 for (int i = 0; i < 2; ++i) {}
115 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
116 // CHECK-NEXT: }
117 #pragma omp target parallel for if (parallel:argc > 0)
118 // CHECK-NEXT: #pragma omp target parallel for if(parallel: argc > 0)
119 for (int i = 0; i < 2; ++i) {}
120 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
121 // CHECK-NEXT: }
122 #pragma omp target parallel for if (N)
123 // CHECK-NEXT: #pragma omp target parallel for if(N)
124 for (int i = 0; i < 2; ++i) {}
125 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
126 // CHECK-NEXT: }
127 #pragma omp target parallel for map(i)
128 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: i)
129 for (int i = 0; i < 2; ++i) {}
130 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
131 // CHECK-NEXT: }
132 #pragma omp target parallel for map(arr1[0:10], i)
133 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: arr1[0:10],i)
134 for (int i = 0; i < 2; ++i) {}
135 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
136 // CHECK-NEXT: }
137 #pragma omp target parallel for map(to: i) map(from: j)
138 // CHECK-NEXT: #pragma omp target parallel for map(to: i) map(from: j)
139 for (int i = 0; i < 2; ++i) {}
140 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
141 // CHECK-NEXT: }
142 #pragma omp target parallel for map(always,alloc: i)
143 // CHECK-NEXT: #pragma omp target parallel for map(always,alloc: i)
144 for (int i = 0; i < 2; ++i) {}
145 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
146 // CHECK-NEXT: }
147 #pragma omp target parallel for nowait
148 // CHECK-NEXT: #pragma omp target parallel for nowait
149 for (int i = 0; i < 2; ++i) {}
150 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
151 // CHECK-NEXT: }
152 #pragma omp target parallel for depend(in : argc, arr[i:argc], arr1[:])
153 // CHECK-NEXT: #pragma omp target parallel for depend(in : argc,arr[i:argc],arr1[:])
154 for (int i = 0; i < 2; ++i) {}
155 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
156 // CHECK-NEXT: }
157 #pragma omp target parallel for defaultmap(tofrom: scalar)
158 // CHECK-NEXT: #pragma omp target parallel for defaultmap(tofrom: scalar)
159 for (int i = 0; i < 2; ++i) {}
160 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
161 // CHECK-NEXT: }
162
163 return T();
164 }
165
main(int argc,char ** argv)166 int main(int argc, char **argv) {
167 int b = argc, c, d, e, f, h;
168 int arr[5][10], arr1[5];
169 int i, j;
170 int s;
171 static int a;
172 // CHECK: static int a;
173 static float g;
174 #pragma omp threadprivate(g)
175 #pragma omp target parallel for schedule(guided, argc) default(none) linear(a)
176 // CHECK: #pragma omp target parallel for schedule(guided, argc) default(none) linear(a)
177 for (int i = 0; i < 2; ++i)
178 a = 2;
179 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
180 // CHECK-NEXT: a = 2;
181 #pragma omp target parallel for 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)
182 for (int i = 0; i < 10; ++i)
183 for (int j = 0; j < 10; ++j)
184 foo();
185 // CHECK-NEXT: #pragma omp target parallel for 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)
186 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
187 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
188 // CHECK-NEXT: foo();
189 #pragma omp target parallel for 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])
190 for (int i = 0; i < 2; ++i) {}
191 // CHECK-NEXT: #pragma omp target parallel for 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])
192 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
193 // CHECK-NEXT: }
194 #pragma omp target parallel for if (5) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:5][:argc]) reduction(&& : h)
195 // CHECK-NEXT: #pragma omp target parallel for if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: h)
196 for (int i = 0; i < 2; ++i) {}
197 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
198 // CHECK-NEXT: }
199 #pragma omp target parallel for if (target:argc > 0)
200 // CHECK-NEXT: #pragma omp target parallel for if(target: argc > 0)
201 for (int i = 0; i < 2; ++i) {}
202 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
203 // CHECK-NEXT: }
204 #pragma omp target parallel for if (parallel:argc > 0)
205 // CHECK-NEXT: #pragma omp target parallel for if(parallel: argc > 0)
206 for (int i = 0; i < 2; ++i) {}
207 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
208 // CHECK-NEXT: }
209 #pragma omp target parallel for if (5)
210 // CHECK-NEXT: #pragma omp target parallel for if(5)
211 for (int i = 0; i < 2; ++i) {}
212 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
213 // CHECK-NEXT: }
214 #pragma omp target parallel for map(i)
215 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: i)
216 for (int i = 0; i < 2; ++i) {}
217 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
218 // CHECK-NEXT: }
219 #pragma omp target parallel for map(arr1[0:10], i)
220 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: arr1[0:10],i)
221 for (int i = 0; i < 2; ++i) {}
222 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
223 // CHECK-NEXT: }
224 #pragma omp target parallel for map(to: i) map(from: j)
225 // CHECK-NEXT: #pragma omp target parallel for map(to: i) map(from: j)
226 for (int i = 0; i < 2; ++i) {}
227 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
228 // CHECK-NEXT: }
229 #pragma omp target parallel for map(always,alloc: i)
230 // CHECK-NEXT: #pragma omp target parallel for map(always,alloc: i)
231 for (int i = 0; i < 2; ++i) {}
232 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
233 // CHECK-NEXT: }
234 #pragma omp target parallel for nowait
235 // CHECK-NEXT: #pragma omp target parallel for nowait
236 for (int i = 0; i < 2; ++i) {}
237 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
238 // CHECK-NEXT: }
239 #pragma omp target parallel for depend(in : argc, arr[i:argc], arr1[:])
240 // CHECK-NEXT: #pragma omp target parallel for depend(in : argc,arr[i:argc],arr1[:])
241 for (int i = 0; i < 2; ++i) {}
242 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
243 // CHECK-NEXT: }
244 #pragma omp target parallel for defaultmap(tofrom: scalar)
245 // CHECK-NEXT: #pragma omp target parallel for defaultmap(tofrom: scalar)
246 for (int i = 0; i < 2; ++i) {}
247 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
248 // CHECK-NEXT: }
249 return (tmain<int, 5>(argc, &argc) + tmain<char, 1>(argv[0][0], argv[0]));
250 }
251
252 #endif
253