1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wsign-conversion | 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
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wsign-conversion | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
9
10 #ifndef HEADER
11 #define HEADER
12
foo()13 void foo() {}
14
15 struct S {
SS16 S(): a(0) {}
SS17 S(int v) : a(v) {}
18 int a;
19 typedef int type;
20 };
21
22 template <typename T>
23 class S7 : public T {
24 protected:
25 T a;
26 T &b;
27 typename T::type c:12;
28 typename T::type &d;
S7()29 S7() : a(0), b(a), c(0), d(a.a) {}
30
31 public:
S7(typename T::type v)32 S7(typename T::type v) : a(v), b(a), c(v), d(a.a) {
33 #pragma omp for private(a) private(this->a) private(T::a)
34 for (int k = 0; k < a.a; ++k)
35 ++this->a.a;
36 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(T::a)
37 for (int k = 0; k < a.a; ++k)
38 ++this->a.a;
39 #pragma omp for linear(val(c))
40 for (int k = 0; k < a.a; ++k)
41 ++this->a.a;
42 }
operator =(S7 & s)43 S7 &operator=(S7 &s) {
44 #pragma omp for private(a) private(this->a)
45 for (int k = 0; k < s.a.a; ++k)
46 ++s.a.a;
47 #pragma omp for lastprivate(a) lastprivate(this->a)
48 for (int k = 0; k < s.a.a; ++k)
49 ++s.a.a;
50 #pragma omp for linear(uval(this->b))
51 for (int k = 0; k < s.a.a; ++k)
52 ++s.a.a;
53 return *this;
54 }
55 };
56
57 // CHECK: #pragma omp for private(this->a) private(this->a) private(T::a)
58 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(T::a)
59 // CHECK: #pragma omp for linear(val(this->c))
60 // CHECK: #pragma omp for private(this->a) private(this->a)
61 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
62 // CHECK: #pragma omp for linear(uval(this->b))
63 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S::a)
64 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S::a)
65 // CHECK: #pragma omp for linear(val(this->c))
66
67 class S8 : public S7<S> {
S8()68 S8() {}
69
70 public:
S8(int v)71 S8(int v) : S7<S>(v){
72 #pragma omp for private(a) private(this->a) private(S7<S>::a)
73 for (int k = 0; k < a.a; ++k)
74 ++this->a.a;
75 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(S7<S>::a)
76 for (int k = 0; k < a.a; ++k)
77 ++this->a.a;
78 #pragma omp for linear(ref(S7<S>::d))
79 for (int k = 0; k < a.a; ++k)
80 ++this->a.a;
81 }
operator =(S8 & s)82 S8 &operator=(S8 &s) {
83 #pragma omp for private(a) private(this->a)
84 for (int k = 0; k < s.a.a; ++k)
85 ++s.a.a;
86 #pragma omp for lastprivate(a) lastprivate(this->a)
87 for (int k = 0; k < s.a.a; ++k)
88 ++s.a.a;
89 #pragma omp for linear(this->c)
90 for (int k = 0; k < s.a.a; ++k)
91 ++s.a.a;
92 return *this;
93 }
94 };
95
96 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S7<S>::a)
97 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S7<S>::a)
98 // CHECK: #pragma omp for linear(ref(this->S7<S>::d))
99 // CHECK: #pragma omp for private(this->a) private(this->a)
100 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
101 // CHECK: #pragma omp for linear(this->c)
102
103 template <class T, int N>
tmain(T argc)104 T tmain(T argc) {
105 T b = argc, c, d, e, f, g;
106 T arr[N];
107 static T a;
108 // CHECK: static T a;
109 #pragma omp for schedule(dynamic) linear(a) allocate(a)
110 // CHECK-NEXT: #pragma omp for schedule(dynamic) linear(a) allocate(a)
111 for (int i = 0; i < 2; ++i)
112 a = 2;
113 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
114 // CHECK-NEXT: a = 2;
115 #pragma omp for schedule(nonmonotonic: dynamic)
116 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: dynamic)
117 for (int i = 0; i < 2; ++i)
118 a = 2;
119 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
120 // CHECK-NEXT: a = 2;
121 #pragma omp for schedule(monotonic : dynamic)
122 // CHECK-NEXT: #pragma omp for schedule(monotonic: dynamic)
123 for (int i = 0; i < 2; ++i)
124 a = 2;
125 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
126 // CHECK-NEXT: a = 2;
127 #pragma omp for schedule(nonmonotonic : guided)
128 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: guided)
129 for (int i = 0; i < 2; ++i)
130 a = 2;
131 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
132 // CHECK-NEXT: a = 2;
133 #pragma omp for schedule(monotonic : guided)
134 // CHECK-NEXT: #pragma omp for schedule(monotonic: guided)
135 for (int i = 0; i < 2; ++i)
136 a = 2;
137 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
138 // CHECK-NEXT: a = 2;
139 #pragma omp for schedule(nonmonotonic : static)
140 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: static)
141 for (int i = 0; i < 2; ++i)
142 a = 2;
143 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
144 // CHECK-NEXT: a = 2;
145 #pragma omp for schedule(monotonic :static)
146 // CHECK-NEXT: #pragma omp for schedule(monotonic: static)
147 for (int i = 0; i < 2; ++i)
148 a = 2;
149 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
150 // CHECK-NEXT: a = 2;
151 #pragma omp for schedule(nonmonotonic : auto)
152 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: auto)
153 for (int i = 0; i < 2; ++i)
154 a = 2;
155 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
156 // CHECK-NEXT: a = 2;
157 #pragma omp for schedule(monotonic : auto)
158 // CHECK-NEXT: #pragma omp for schedule(monotonic: auto)
159 for (int i = 0; i < 2; ++i)
160 a = 2;
161 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
162 // CHECK-NEXT: a = 2;
163 #pragma omp for schedule(nonmonotonic : runtime)
164 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: runtime)
165 for (int i = 0; i < 2; ++i)
166 a = 2;
167 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
168 // CHECK-NEXT: a = 2;
169 #pragma omp for schedule(monotonic : runtime)
170 // CHECK-NEXT: #pragma omp for schedule(monotonic: runtime)
171 for (int i = 0; i < 2; ++i)
172 a = 2;
173 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
174 // CHECK-NEXT: a = 2;
175 #pragma omp parallel
176 #pragma omp for allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) nowait
177 for (auto &x : arr) {
178 int j, hhh = 0;
179 for (int i = 0; i < 2; ++i) {
180 int j, hhh = 0;
181 for (int j = 0; j < 2; ++j)
182 for (int j = 0; j < 2; ++j)
183 for (int j = 0; j < 2; ++j)
184 for (int j = 0; j < 2; ++j)
185 for (int i = 0; i < 2; ++i)
186 for (int j = 0; j < 2; ++j)
187 for (int j = 0; j < 2; ++j)
188 for (int j = 0; j < 2; ++j)
189 for (int j = 0; j < 2; ++j)
190 foo();
191 ++hhh;
192 }
193 ++hhh;
194 }
195 // CHECK-NEXT: #pragma omp parallel
196 // CHECK-NEXT: #pragma omp for allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) nowait
197 // CHECK-NEXT: for (auto &x : arr) {
198 // CHECK-NEXT: int j, hhh = 0;
199 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
200 // CHECK-NEXT: int j, hhh = 0;
201 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
202 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
203 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
204 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
205 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
206 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
207 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
208 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
209 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
210 // CHECK-NEXT: foo();
211 // CHECK-NEXT: ++hhh;
212 // CHECK-NEXT: }
213 // CHECK-NEXT: ++hhh;
214 // CHECK-NEXT: }
215 return T();
216 }
217
main(int argc,char ** argv)218 int main(int argc, char **argv) {
219 // CHECK: int main(int argc, char **argv) {
220 int b = argc, c, d, e, f, g;
221 float arr[20];
222 static int a;
223 // CHECK: static int a;
224 #pragma omp for schedule(guided, argc) reduction(+:argv[0][:1]) order(concurrent)
225 // CHECK-NEXT: #pragma omp for schedule(guided, argc) reduction(+: argv[0][:1]) order(concurrent)
226 for (int i = argc; i < c; ++i)
227 a = 2;
228 // CHECK-NEXT: for (int i = argc; i < c; ++i)
229 // CHECK-NEXT: a = 2;
230 #pragma omp parallel
231 #pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(3) schedule(auto) ordered nowait linear(g:-1) reduction(task, +:e)
232 for (int i = 0; i < 10; ++i)
233 for (int j = 0; j < 10; ++j)
234 for (auto x : arr)
235 foo(), (void)x;
236 // CHECK-NEXT: #pragma omp parallel
237 // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(3) schedule(auto) ordered nowait linear(g: -1) reduction(task, +: e)
238 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
239 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
240 // CHECK-NEXT: for (auto x : arr)
241 // CHECK-NEXT: foo() , (void)x;
242 char buf[9] = "01234567";
243 char *p, *q;
244 #pragma omp parallel
245 #pragma omp for
246 for (p = buf; p < &buf[8]; p++)
247 for (q = &buf[0]; q <= buf + 7; q++)
248 foo();
249 // CHECK: #pragma omp parallel
250 // CHECK-NEXT: #pragma omp for{{$}}
251 // CHECK-NEXT: for (p = buf; p < &buf[8]; p++)
252 // CHECK-NEXT: for (q = &buf[0]; q <= buf + 7; q++)
253 // CHECK-NEXT: foo();
254 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
255 }
256
257 #endif
258