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
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | 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 S1 {
S1S116 S1(): a(0) {}
S1S117 S1(int v) : a(v) {}
18 int a;
19 typedef int type;
20 S1& operator +(const S1&);
21 S1& operator *(const S1&);
22 S1& operator &&(const S1&);
23 S1& operator ^(const S1&);
24 };
25
26 template <typename T>
27 class S7 : public T {
28 protected:
29 T a;
30 T b[100];
S7()31 S7() : a(0) {}
32
33 public:
S7(typename T::type v)34 S7(typename T::type v) : a(v) {
35 #pragma omp parallel private(a) private(this->a) private(T::a)
36 for (int k = 0; k < a.a; ++k)
37 ++this->a.a;
38 #pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(T::a)
39 for (int k = 0; k < a.a; ++k)
40 ++this->a.a;
41 #pragma omp parallel shared(a) shared(this->a) shared(T::a)
42 for (int k = 0; k < a.a; ++k)
43 ++this->a.a;
44 #pragma omp parallel reduction(+ : a) reduction(*: b[:])
45 for (int k = 0; k < a.a; ++k)
46 ++this->a.a;
47 }
operator =(S7 & s)48 S7 &operator=(S7 &s) {
49 #pragma omp parallel private(a) private(this->a)
50 for (int k = 0; k < s.a.a; ++k)
51 ++s.a.a;
52 #pragma omp parallel firstprivate(a) firstprivate(this->a)
53 for (int k = 0; k < s.a.a; ++k)
54 ++s.a.a;
55 #pragma omp parallel shared(a) shared(this->a)
56 for (int k = 0; k < s.a.a; ++k)
57 ++s.a.a;
58 #pragma omp parallel reduction(&& : this->a) reduction(^: b[s.a.a])
59 for (int k = 0; k < s.a.a; ++k)
60 ++s.a.a;
61 return *this;
62 }
63 };
64
65 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(T::a)
66 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(T::a)
67 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(T::a)
68 // CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:])
69 // CHECK: #pragma omp parallel private(this->a) private(this->a)
70 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a)
71 // CHECK: #pragma omp parallel shared(this->a) shared(this->a)
72 // CHECK: #pragma omp parallel reduction(&&: this->a) reduction(^: this->b[s.a.a])
73 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S1::a)
74 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a)
75 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S1::a)
76 // CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:])
77
78 class S8 : public S7<S1> {
S8()79 S8() {}
80
81 public:
S8(int v)82 S8(int v) : S7<S1>(v){
83 #pragma omp parallel private(a) private(this->a) private(S7 < S1 > ::a)
84 for (int k = 0; k < a.a; ++k)
85 ++this->a.a;
86 #pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a)
87 for (int k = 0; k < a.a; ++k)
88 ++this->a.a;
89 #pragma omp parallel shared(a) shared(this->a) shared(S7 < S1 > ::a)
90 for (int k = 0; k < a.a; ++k)
91 ++this->a.a;
92 #pragma omp parallel reduction(default, ^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a])
93 for (int k = 0; k < a.a; ++k)
94 ++this->a.a;
95 }
operator =(S8 & s)96 S8 &operator=(S8 &s) {
97 #pragma omp parallel private(a) private(this->a)
98 for (int k = 0; k < s.a.a; ++k)
99 ++s.a.a;
100 #pragma omp parallel firstprivate(a) firstprivate(this->a)
101 for (int k = 0; k < s.a.a; ++k)
102 ++s.a.a;
103 #pragma omp parallel shared(a) shared(this->a)
104 for (int k = 0; k < s.a.a; ++k)
105 ++s.a.a;
106 #pragma omp parallel reduction(* : this->a) reduction(&&:this->b[a.a:])
107 for (int k = 0; k < s.a.a; ++k)
108 ++s.a.a;
109 return *this;
110 }
111 };
112
113 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S7<S1>::a)
114 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7<S1>::a)
115 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S7<S1>::a)
116 // CHECK: #pragma omp parallel reduction(default, ^: this->S7<S1>::a) reduction(+: this->S7<S1>::b[:this->S7<S1>::a.a])
117 // CHECK: #pragma omp parallel private(this->a) private(this->a)
118 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a)
119 // CHECK: #pragma omp parallel shared(this->a) shared(this->a)
120 // CHECK: #pragma omp parallel reduction(*: this->a) reduction(&&: this->b[this->a.a:])
121
122 template <class T>
123 struct S {
operator TS124 operator T() {return T();}
125 static T TS;
126 #pragma omp threadprivate(TS)
127 };
128
129 // CHECK: template <class T> struct S {
130 // CHECK: static T TS;
131 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
132 // CHECK: };
133 // CHECK: template<> struct S<int> {
134 // CHECK: static int TS;
135 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
136 // CHECK-NEXT: }
137 // CHECK: template<> struct S<long> {
138 // CHECK: static long TS;
139 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
140 // CHECK-NEXT: }
141
142 int thrp;
143 #pragma omp threadprivate(thrp)
144
145 template <typename T, int C>
tmain(T argc,T * argv)146 T tmain(T argc, T *argv) {
147 T b = argc, c, d, e, f, g;
148 static T a;
149 S<T> s;
150 T arr[C][10], arr1[C];
151 #pragma omp parallel
152 a=2;
153 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS, thrp) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10])
154 foo();
155 #pragma omp parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(default, && : g) reduction(task,+:argc)
156 foo();
157 return 0;
158 }
159
160 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
161 // CHECK-NEXT: T b = argc, c, d, e, f, g;
162 // CHECK-NEXT: static T a;
163 // CHECK-NEXT: S<T> s;
164 // CHECK-NEXT: T arr[C][10], arr1[C];
165 // CHECK-NEXT: #pragma omp parallel{{$}}
166 // CHECK-NEXT: a = 2;
167 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10])
168 // CHECK-NEXT: foo()
169 // CHECK-NEXT: #pragma omp parallel if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(default, &&: g) reduction(task, +: argc)
170 // CHECK-NEXT: foo()
171 // CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
172 // CHECK-NEXT: int b = argc, c, d, e, f, g;
173 // CHECK-NEXT: static int a;
174 // CHECK-NEXT: S<int> s;
175 // CHECK-NEXT: int arr[5][10], arr1[5];
176 // CHECK-NEXT: #pragma omp parallel
177 // CHECK-NEXT: a = 2;
178 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
179 // CHECK-NEXT: foo()
180 // CHECK-NEXT: #pragma omp parallel if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(default, &&: g) reduction(task, +: argc)
181 // CHECK-NEXT: foo()
182 // CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
183 // CHECK-NEXT: long b = argc, c, d, e, f, g;
184 // CHECK-NEXT: static long a;
185 // CHECK-NEXT: S<long> s;
186 // CHECK-NEXT: long arr[1][10], arr1[1];
187 // CHECK-NEXT: #pragma omp parallel
188 // CHECK-NEXT: a = 2;
189 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10])
190 // CHECK-NEXT: foo()
191 // CHECK-NEXT: #pragma omp parallel if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(default, &&: g) reduction(task, +: argc)
192 // CHECK-NEXT: foo()
193
194 enum Enum { };
195
main(int argc,char ** argv)196 int main (int argc, char **argv) {
197 long x;
198 int b = argc, c, d, e, f, g;
199 static int a;
200 #pragma omp threadprivate(a)
201 int arr[10][argc], arr1[2];
202 Enum ee;
203 // CHECK: Enum ee;
204 #pragma omp parallel
205 // CHECK-NEXT: #pragma omp parallel
206 a=2;
207 // CHECK-NEXT: a = 2;
208 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e)
209 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) allocate(e)
210 foo();
211 // CHECK-NEXT: foo();
212 // CHECK-NEXT: #pragma omp parallel allocate(e) if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10])
213 // CHECK-NEXT: foo()
214 #pragma omp parallel allocate(e) if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10])
215 foo();
216 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
217 }
218
219 template <class T>
220 struct Foo {
221 int foo;
222 };
223
foo(const Foo<int> & arg)224 void foo(const Foo<int> &arg) {
225 // CHECK: #pragma omp parallel
226 #pragma omp parallel
227 {
228 // CHECK: #pragma omp for schedule(static)
229 #pragma omp for schedule(static)
230 for (int idx = 0; idx < 1234; ++idx) {
231 //arg.foo = idx;
232 idx = arg.foo;
233 }
234 }
235 }
236
237 template<typename T>
238 T S<T>::TS = 0;
239
240 #endif
241