blob: b20ff0a426a721238ea9be224b00bf8dd98c6786 [file] [log] [blame]
Kelvin Li986330c2016-07-20 22:57:10 +00001// RUN: %clang_cc1 -verify -fopenmp %s
2
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
14
15public:
16 S2() : a(0) {}
17};
18const S2 b;
19const S2 ba[5];
20class S3 {
21 int a;
22
23public:
24 S3() : a(0) {}
25};
26const S3 ca[5];
27class S4 {
28 int a;
29 S4(); // expected-note {{implicitly declared private here}}
30
31public:
32 S4(int v) : a(v) {
33#pragma omp target simd private(a) private(this->a)
34 for (int k = 0; k < v; ++k)
35 ++this->a;
36 }
37};
38class S5 {
39 int a;
40 S5() : a(0) {} // expected-note {{implicitly declared private here}}
41
42public:
43 S5(int v) : a(v) {}
44 S5 &operator=(S5 &s) {
45#pragma omp target simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
46 for (int k = 0; k < s.a; ++k)
47 ++s.a;
48 return *this;
49 }
50};
51
52template <typename T>
53class S6 {
54public:
55 T a;
56
57 S6() : a(0) {}
58 S6(T v) : a(v) {
59#pragma omp target simd private(a) private(this->a)
60 for (int k = 0; k < v; ++k)
61 ++this->a;
62 }
63 S6 &operator=(S6 &s) {
64#pragma omp target simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
65 for (int k = 0; k < s.a; ++k)
66 ++s.a;
67 return *this;
68 }
69};
70
71template <typename T>
72class S7 : public T {
73 T a;
74 S7() : a(0) {}
75
76public:
77 S7(T v) : a(v) {
78#pragma omp target simd private(a) private(this->a) private(T::a)
79 for (int k = 0; k < a.a; ++k)
80 ++this->a.a;
81 }
82 S7 &operator=(S7 &s) {
83#pragma omp target simd private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
84 for (int k = 0; k < s.a.a; ++k)
85 ++s.a.a;
86 return *this;
87 }
88};
89
90S3 h;
91#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
92
93template <class I, class C>
94int foomain(I argc, C **argv) {
95 I e(4);
96 I g(5);
97 int i;
98 int &j = i;
99#pragma omp target simd private // expected-error {{expected '(' after 'private'}}
100 for (int k = 0; k < argc; ++k)
101 ++k;
102#pragma omp target simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
103 for (int k = 0; k < argc; ++k)
104 ++k;
105#pragma omp target simd private() // expected-error {{expected expression}}
106 for (int k = 0; k < argc; ++k)
107 ++k;
108#pragma omp target simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
109 for (int k = 0; k < argc; ++k)
110 ++k;
111#pragma omp target simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
112 for (int k = 0; k < argc; ++k)
113 ++k;
114#pragma omp target simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
115 for (int k = 0; k < argc; ++k)
116 ++k;
117#pragma omp target simd private(argc)
118 for (int k = 0; k < argc; ++k)
119 ++k;
120#pragma omp target simd private(S1) // expected-error {{'S1' does not refer to a value}}
121 for (int k = 0; k < argc; ++k)
122 ++k;
123#pragma omp target simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
124 for (int k = 0; k < argc; ++k)
125 ++k;
126#pragma omp target simd private(argv[1]) // expected-error {{expected variable name}}
127 for (int k = 0; k < argc; ++k)
128 ++k;
129#pragma omp target simd private(e, g)
130 for (int k = 0; k < argc; ++k)
131 ++k;
132#pragma omp target simd private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
133 for (int k = 0; k < argc; ++k)
134 ++k;
135#pragma omp parallel
136 {
137 int v = 0;
138 int i;
139#pragma omp target simd private(i)
140 for (int k = 0; k < argc; ++k) {
141 i = k;
142 v += i;
143 }
144 }
145#pragma omp parallel shared(i)
146#pragma omp parallel private(i)
147#pragma omp target simd private(j)
148 for (int k = 0; k < argc; ++k)
149 ++k;
150#pragma omp target simd private(i)
151 for (int k = 0; k < argc; ++k)
152 ++k;
153 return 0;
154}
155
156namespace A {
157double x;
158#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
159}
160namespace B {
161using A::x;
162}
163
164int main(int argc, char **argv) {
165 S4 e(4);
166 S5 g(5);
167 S6<float> s6(0.0) , s6_0(1.0);
168 S7<S6<float> > s7(0.0) , s7_0(1.0);
169 int i;
170 int &j = i;
171#pragma omp target simd private // expected-error {{expected '(' after 'private'}}
172 for (int k = 0; k < argc; ++k)
173 ++k;
174#pragma omp target simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
175 for (int k = 0; k < argc; ++k)
176 ++k;
177#pragma omp target simd private() // expected-error {{expected expression}}
178 for (int k = 0; k < argc; ++k)
179 ++k;
180#pragma omp target simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
181 for (int k = 0; k < argc; ++k)
182 ++k;
183#pragma omp target simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
184 for (int k = 0; k < argc; ++k)
185 ++k;
186#pragma omp target simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
187 for (int k = 0; k < argc; ++k)
188 ++k;
189#pragma omp target simd private(argc)
190 for (int k = 0; k < argc; ++k)
191 ++k;
192#pragma omp target simd private(S1) // expected-error {{'S1' does not refer to a value}}
193 for (int k = 0; k < argc; ++k)
194 ++k;
195#pragma omp target simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
196 for (int k = 0; k < argc; ++k)
197 ++k;
198#pragma omp target simd private(argv[1]) // expected-error {{expected variable name}}
199 for (int k = 0; k < argc; ++k)
200 ++k;
201#pragma omp target simd private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
202 for (int k = 0; k < argc; ++k)
203 ++k;
204#pragma omp target simd private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
205 for (int k = 0; k < argc; ++k)
206 ++k;
207#pragma omp parallel
208 {
209 int i;
210#pragma omp target simd private(i)
211 for (int k = 0; k < argc; ++k)
212 ++k;
213 }
214#pragma omp parallel shared(i)
215#pragma omp parallel private(i)
216#pragma omp target simd private(j)
217 for (int k = 0; k < argc; ++k)
218 ++k;
219#pragma omp target simd private(i)
220 for (int k = 0; k < argc; ++k)
221 ++k;
222 static int m;
223#pragma omp target simd private(m)
224 for (int k = 0; k < argc; ++k)
225 m = k + 2;
226
227 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
228 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
229 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
230}
231