1 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7
8 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
9 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
11 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
13 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
14 // expected-no-diagnostics
15
16 #ifndef HEADER
17 #define HEADER
18
19 struct S {
SS20 S(): a(0) {}
SS21 S(int v) : a(v) {}
22 int a;
23 typedef int type;
24 };
25
26 template <typename T>
27 class S7 : public T {
28 protected:
29 T a;
S7()30 S7() : a(0) {}
31
32 public:
S7(typename T::type v)33 S7(typename T::type v) : a(v) {
34 #pragma omp target
35 #pragma omp teams
36 #pragma omp distribute parallel for private(a) private(this->a) private(T::a)
37 for (int k = 0; k < a.a; ++k)
38 ++this->a.a;
39 }
operator =(S7 & s)40 S7 &operator=(S7 &s) {
41 #pragma omp target
42 #pragma omp teams
43 #pragma omp distribute parallel for private(a) private(this->a)
44 for (int k = 0; k < s.a.a; ++k)
45 ++s.a.a;
46 return *this;
47 }
48 };
49
50 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(T::a){{$}}
51 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a)
52 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S::a)
53
54 class S8 : public S7<S> {
S8()55 S8() {}
56
57 public:
S8(int v)58 S8(int v) : S7<S>(v){
59 #pragma omp target
60 #pragma omp teams
61 #pragma omp distribute parallel for private(a) private(this->a) private(S7<S>::a)
62 for (int k = 0; k < a.a; ++k)
63 ++this->a.a;
64 }
operator =(S8 & s)65 S8 &operator=(S8 &s) {
66 #pragma omp target
67 #pragma omp teams
68 #pragma omp distribute parallel for private(a) private(this->a)
69 for (int k = 0; k < s.a.a; ++k)
70 ++s.a.a;
71 return *this;
72 }
73 };
74
75 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S7<S>::a)
76 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a)
77
78 template <class T, int N>
tmain(T argc)79 T tmain(T argc) {
80 T b = argc, c, d, e, f, h;
81 static T a;
82 // CHECK: static T a;
83 static T g;
84 #pragma omp threadprivate(g)
85 #pragma omp target
86 #pragma omp teams
87 #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
88 // CHECK: #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
89 for (int i = 0; i < 2; ++i)
90 a = 2;
91 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
92 // CHECK-NEXT: a = 2;
93 #pragma omp target
94 #pragma omp teams
95 #pragma omp distribute parallel for allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
96 for (int i = 0; i < 2; ++i)
97 for (int j = 0; j < 2; ++j)
98 for (int j = 0; j < 2; ++j)
99 for (int j = 0; j < 2; ++j)
100 for (int j = 0; j < 2; ++j)
101 for (int i = 0; i < 2; ++i)
102 for (int j = 0; j < 2; ++j)
103 for (int j = 0; j < 2; ++j)
104 for (int j = 0; j < 2; ++j)
105 for (int j = 0; j < 2; ++j)
106 a++;
107 // CHECK: #pragma omp distribute parallel for allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
108 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
109 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
110 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
111 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
112 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
113 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
114 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
115 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
116 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
117 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
118 // CHECK-NEXT: a++;
119 return T();
120 }
121
foo(int argc,char ** argv)122 void foo(int argc, char **argv) {
123 int b, c, d, e, f, h;
124 static int a;
125 // CHECK: static int a;
126 static float g;
127 #pragma omp threadprivate(g)
128 [&]() {
129 #pragma omp target
130 #pragma omp teams
131 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
132 // CHECK: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
133 for (int i = 0; i < 2; ++i)
134 // CHECK: for (int i = 0; i < 2; ++i)
135 [&]() {
136 a = 2;
137 // CHECK: a = 2;
138 }();
139
140 }();
141 [&]() {
142 #pragma omp target
143 #pragma omp teams
144 #pragma omp distribute parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
145 for (int i = 0; i < 10; ++i)
146 for (int j = 0; j < 10; ++j)
147 [&]() {
148 a++;
149 }();
150 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
151 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
152 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
153 // CHECK: a++;
154 }();
155 }
156
main(int argc,char ** argv)157 int main(int argc, char **argv) {
158 int b = argc, c, d, e, f, h;
159 static int a;
160 // CHECK: static int a;
161 static float g;
162 #pragma omp threadprivate(g)
163 #pragma omp target
164 #pragma omp teams
165 #ifdef OMP5
166 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(concurrent) reduction(task,+:c)
167 #else
168 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
169 #endif // OMP5
170 // OMP45: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
171 // OMP50: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(concurrent) reduction(task, +: c)
172 for (int i = 0; i < 2; ++i)
173 a = 2;
174 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
175 // CHECK-NEXT: a = 2;
176 #pragma omp target
177 #pragma omp teams
178 #pragma omp distribute parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
179 for (int i = 0; i < 10; ++i)
180 for (int j = 0; j < 10; ++j)
181 a++;
182 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
183 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
184 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
185 // CHECK-NEXT: a++;
186 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
187 }
188
189 #endif
190