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;
22 T &b;
23 typename T::type c:12;
24 typename T::type &d;
S7()25 S7() : a(0), b(a), c(0), d(a.a) {}
26
27 public:
S7(typename T::type v)28 S7(typename T::type v) : a(v), b(a), c(v), d(a.a) {
29 #pragma omp for private(a) private(this->a) private(T::a)
30 for (int k = 0; k < a.a; ++k)
31 ++this->a.a;
32 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(T::a)
33 for (int k = 0; k < a.a; ++k)
34 ++this->a.a;
35 #pragma omp for linear(val(c))
36 for (int k = 0; k < a.a; ++k)
37 ++this->a.a;
38 }
operator =(S7 & s)39 S7 &operator=(S7 &s) {
40 #pragma omp for private(a) private(this->a)
41 for (int k = 0; k < s.a.a; ++k)
42 ++s.a.a;
43 #pragma omp for lastprivate(a) lastprivate(this->a)
44 for (int k = 0; k < s.a.a; ++k)
45 ++s.a.a;
46 #pragma omp for linear(uval(this->b))
47 for (int k = 0; k < s.a.a; ++k)
48 ++s.a.a;
49 return *this;
50 }
51 };
52
53 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S::a)
54 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S::a)
55 // CHECK: #pragma omp for linear(val(this->c))
56 // CHECK: #pragma omp for private(this->a) private(this->a) private(T::a)
57 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(T::a)
58 // CHECK: #pragma omp for linear(val(this->c))
59 // CHECK: #pragma omp for private(this->a) private(this->a)
60 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
61 // CHECK: #pragma omp for linear(uval(this->b))
62
63 class S8 : public S7<S> {
S8()64 S8() {}
65
66 public:
S8(int v)67 S8(int v) : S7<S>(v){
68 #pragma omp for private(a) private(this->a) private(S7<S>::a)
69 for (int k = 0; k < a.a; ++k)
70 ++this->a.a;
71 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(S7<S>::a)
72 for (int k = 0; k < a.a; ++k)
73 ++this->a.a;
74 #pragma omp for linear(ref(S7<S>::d))
75 for (int k = 0; k < a.a; ++k)
76 ++this->a.a;
77 }
operator =(S8 & s)78 S8 &operator=(S8 &s) {
79 #pragma omp for private(a) private(this->a)
80 for (int k = 0; k < s.a.a; ++k)
81 ++s.a.a;
82 #pragma omp for lastprivate(a) lastprivate(this->a)
83 for (int k = 0; k < s.a.a; ++k)
84 ++s.a.a;
85 #pragma omp for linear(this->c)
86 for (int k = 0; k < s.a.a; ++k)
87 ++s.a.a;
88 return *this;
89 }
90 };
91
92 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S7<S>::a)
93 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S7<S>::a)
94 // CHECK: #pragma omp for linear(ref(this->S7<S>::d))
95 // CHECK: #pragma omp for private(this->a) private(this->a)
96 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
97 // CHECK: #pragma omp for linear(this->c)
98
99 template <class T, int N>
tmain(T argc)100 T tmain(T argc) {
101 T b = argc, c, d, e, f, g;
102 static T a;
103 // CHECK: static T a;
104 #pragma omp for schedule(dynamic) linear(a)
105 // CHECK-NEXT: #pragma omp for schedule(dynamic) linear(a)
106 for (int i = 0; i < 2; ++i)
107 a = 2;
108 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
109 // CHECK-NEXT: a = 2;
110 #pragma omp parallel
111 #pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) nowait
112 for (int i = 0; i < 2; ++i)
113 for (int j = 0; j < 2; ++j)
114 for (int j = 0; j < 2; ++j)
115 for (int j = 0; j < 2; ++j)
116 for (int j = 0; j < 2; ++j)
117 for (int i = 0; i < 2; ++i)
118 for (int j = 0; j < 2; ++j)
119 for (int j = 0; j < 2; ++j)
120 for (int j = 0; j < 2; ++j)
121 for (int j = 0; j < 2; ++j)
122 foo();
123 // CHECK-NEXT: #pragma omp parallel
124 // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) nowait
125 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
126 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
127 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
128 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
129 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
130 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
131 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
132 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
133 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
134 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
135 // CHECK-NEXT: foo();
136 return T();
137 }
138
main(int argc,char ** argv)139 int main(int argc, char **argv) {
140 int b = argc, c, d, e, f, g;
141 static int a;
142 // CHECK: static int a;
143 #pragma omp for schedule(guided, argc)
144 // CHECK-NEXT: #pragma omp for schedule(guided, argc)
145 for (int i = 0; i < 2; ++i)
146 a = 2;
147 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
148 // CHECK-NEXT: a = 2;
149 #pragma omp parallel
150 #pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered nowait linear(g:-1)
151 for (int i = 0; i < 10; ++i)
152 for (int j = 0; j < 10; ++j)
153 foo();
154 // CHECK-NEXT: #pragma omp parallel
155 // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered nowait linear(g: -1)
156 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
157 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
158 // CHECK-NEXT: foo();
159 char buf[9] = "01234567";
160 char *p, *q;
161 #pragma omp parallel
162 #pragma omp for
163 for (p = buf; p < &buf[8]; p++)
164 for (q = &buf[0]; q <= buf + 7; q++)
165 foo();
166 // CHECK: #pragma omp parallel
167 // CHECK-NEXT: #pragma omp for
168 // CHECK-NEXT: for (p = buf; p < &buf[8]; p++)
169 // CHECK-NEXT: for (q = &buf[0]; q <= buf + 7; q++)
170 // CHECK-NEXT: foo();
171 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
172 }
173
174 #endif
175