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