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
9 struct S {
SS10 S(): a(0) {}
SS11 S(int v) : a(v) {}
12 int a;
13 typedef int type;
14 };
15
16 template <typename T>
17 class S7 : public T {
18 protected:
19 T a;
S7()20 S7() : a(0) {}
21
22 public:
S7(typename T::type v)23 S7(typename T::type v) : a(v) {
24 #pragma omp target
25 #pragma omp teams
26 #pragma omp distribute 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
32 #pragma omp teams
33 #pragma omp distribute simd private(a) private(this->a)
34 for (int k = 0; k < s.a.a; ++k)
35 ++s.a.a;
36 return *this;
37 }
38 };
39
40 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S::a)
41 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(T::a)
42 // CHECK: #pragma omp distribute simd private(this->a) private(this->a)
43
44 class S8 : public S7<S> {
S8()45 S8() {}
46
47 public:
S8(int v)48 S8(int v) : S7<S>(v){
49 #pragma omp target
50 #pragma omp teams
51 #pragma omp distribute simd private(a) private(this->a) private(S7<S>::a)
52 for (int k = 0; k < a.a; ++k)
53 ++this->a.a;
54 }
operator =(S8 & s)55 S8 &operator=(S8 &s) {
56 #pragma omp target
57 #pragma omp teams
58 #pragma omp distribute simd private(a) private(this->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 distribute simd private(this->a) private(this->a) private(this->S7<S>::a)
66 // CHECK: #pragma omp distribute simd private(this->a) private(this->a)
67
68 template <class T, int N>
tmain(T argc)69 T tmain(T argc) {
70 T b = argc, c, d, e, f, h;
71 static T a;
72 // CHECK: static T a;
73 static T g;
74 #pragma omp threadprivate(g)
75
76 #pragma omp target
77 #pragma omp teams
78 #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
79 for (int i = 0; i < 2; ++i)
80 a = 2;
81 // CHECK: #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
82 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
83 // CHECK-NEXT: a = 2;
84
85 #pragma omp target
86 #pragma omp teams
87 #pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) reduction(+ : h) dist_schedule(static,N)
88 for (int i = 0; i < 2; ++i)
89 for (int j = 0; j < 2; ++j)
90 for (int k = 0; k < 10; ++k)
91 for (int m = 0; m < 10; ++m)
92 for (int n = 0; n < 10; ++n)
93 a++;
94 // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) reduction(+: h) dist_schedule(static, N)
95 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
96 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
97 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
98 // CHECK-NEXT: for (int m = 0; m < 10; ++m)
99 // CHECK-NEXT: for (int n = 0; n < 10; ++n)
100 // CHECK-NEXT: a++;
101 return T();
102 }
103
main(int argc,char ** argv)104 int main(int argc, char **argv) {
105 int b = argc, c, d, e, f, h;
106 int x[200];
107 static int a;
108 // CHECK: static int a;
109 static float g;
110 #pragma omp threadprivate(g)
111
112 #pragma omp target
113 #pragma omp teams
114 #pragma omp distribute simd dist_schedule(static, a) private(a)
115 for (int i = 0; i < 2; ++i)
116 a = 2;
117 // CHECK: #pragma omp distribute simd dist_schedule(static, a) private(a)
118 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
119 // CHECK-NEXT: a = 2;
120
121 #pragma omp target
122 #pragma omp teams
123 #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b)
124 for (int i = 0; i < 10; ++i)
125 for (int j = 0; j < 10; ++j)
126 a++;
127 // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b)
128 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
129 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
130 // CHECK-NEXT: a++;
131
132 #pragma omp target
133 #pragma omp teams
134 #pragma omp distribute simd aligned(x:8) linear(h:2) safelen(8) simdlen(8)
135 for (int i = 0; i < 100; i++)
136 for (int j = 0; j < 200; j++)
137 a += h + x[j];
138 // CHECK: #pragma omp distribute simd aligned(x: 8) linear(h: 2) safelen(8) simdlen(8)
139 // CHECK-NEXT: for (int i = 0; i < 100; i++)
140 // CHECK-NEXT: for (int j = 0; j < 200; j++)
141 // CHECK-NEXT: a += h + x[j];
142
143 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
144 }
145
146 #endif
147