blob: 793b4d5d0a5f8afe8da8d595969f707277e50821 [file] [log] [blame]
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
2
3void foo() {
4}
5
6struct S1; // expected-note 2 {{declared here}}
7class S2 {
8 mutable int a;
9
10public:
11 S2() : a(0) {}
12 S2 &operator=(S2 &s2) { return *this; }
13};
14class S3 {
15 int a;
16
17public:
18 S3() : a(0) {}
19 S3 &operator=(S3 &s3) { return *this; }
20};
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070021class S4 {
Stephen Hinesc568f1e2014-07-21 00:47:37 -070022 int a;
23 S4();
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070024 S4 &operator=(const S4 &s4); // expected-note 3 {{implicitly declared private here}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -070025
26public:
27 S4(int v) : a(v) {}
28};
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070029class S5 {
Stephen Hinesc568f1e2014-07-21 00:47:37 -070030 int a;
31 S5() : a(0) {}
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070032 S5 &operator=(const S5 &s5) { return *this; } // expected-note 3 {{implicitly declared private here}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -070033
34public:
35 S5(int v) : a(v) {}
36};
37
38S2 k;
39S3 h;
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070040S4 l(3);
41S5 m(4);
Stephen Hinesc568f1e2014-07-21 00:47:37 -070042#pragma omp threadprivate(h, k, l, m)
43
44template <class T, class C>
45T tmain(T argc, C **argv) {
46 T i;
Stephen Hines0e2c34f2015-03-23 12:09:02 -070047 static T TA;
Stephen Hinesc568f1e2014-07-21 00:47:37 -070048#pragma omp parallel
49#pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
50#pragma omp parallel
51#pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
52#pragma omp parallel
53#pragma omp single copyprivate() // expected-error {{expected expression}}
54#pragma omp parallel
55#pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
56#pragma omp parallel
57#pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
58#pragma omp parallel
59#pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
60#pragma omp parallel
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070061#pragma omp single copyprivate(l) // expected-error 2 {{'operator=' is a private member of 'S4'}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -070062#pragma omp parallel
63#pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
64#pragma omp parallel
65#pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
66#pragma omp parallel // expected-note {{implicitly determined as shared}}
67#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
68#pragma omp parallel
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070069#pragma omp single copyprivate(m) // expected-error 2 {{'operator=' is a private member of 'S5'}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -070070 foo();
71#pragma omp parallel private(i)
72 {
73#pragma omp single copyprivate(i)
74 foo();
75 }
76#pragma omp parallel shared(i) // expected-note {{defined as shared}}
77 {
78#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
79 foo();
80 }
81#pragma omp parallel private(i)
82#pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
83 {
84#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
85 foo();
86 }
87#pragma omp parallel private(i)
88#pragma omp parallel // expected-note {{implicitly determined as shared}}
89 {
90#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
91 foo();
92 }
93#pragma omp parallel
94#pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
95 foo();
96#pragma omp parallel
97#pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
98 foo();
Stephen Hines0e2c34f2015-03-23 12:09:02 -070099#pragma omp parallel private(TA)
100 {
101#pragma omp single copyprivate(TA)
102 TA = 99;
103 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700104
105 return T();
106}
107
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700108namespace A {
109double x;
110#pragma omp threadprivate(x)
111}
112namespace B {
113using A::x;
114}
115
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700116int main(int argc, char **argv) {
117 int i;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700118 static int intA;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700119#pragma omp parallel
120#pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
121#pragma omp parallel
122#pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
123#pragma omp parallel
124#pragma omp single copyprivate() // expected-error {{expected expression}}
125#pragma omp parallel
126#pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
127#pragma omp parallel
128#pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
129#pragma omp parallel
130#pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
131#pragma omp parallel
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700132#pragma omp single copyprivate(l, B::x) // expected-error {{'operator=' is a private member of 'S4'}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700133#pragma omp parallel
134#pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
135#pragma omp parallel
136#pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
137#pragma omp parallel // expected-note {{implicitly determined as shared}}
138#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
139#pragma omp parallel
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700140#pragma omp single copyprivate(m) // expected-error {{'operator=' is a private member of 'S5'}}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700141 foo();
142#pragma omp parallel private(i)
143 {
144#pragma omp single copyprivate(i)
145 foo();
146 }
147#pragma omp parallel shared(i) // expected-note {{defined as shared}}
148 {
149#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
150 foo();
151 }
152#pragma omp parallel private(i)
153#pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
154 {
155#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
156 foo();
157 }
158#pragma omp parallel private(i)
159#pragma omp parallel // expected-note {{implicitly determined as shared}}
160 {
161#pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
162 foo();
163 }
164#pragma omp parallel
165#pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
166 foo();
167#pragma omp parallel
168#pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
169 foo();
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700170#pragma omp single copyprivate(i) nowait // expected-error {{the 'copyprivate' clause must not be used with the 'nowait' clause}} expected-note {{'nowait' clause is here}}
171 foo();
172#pragma omp parallel private(intA)
173 {
174#pragma omp single copyprivate(intA)
175 intA = 99;
176 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700177
178 return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}}
179}
Stephen Hines176edba2014-12-01 14:53:08 -0800180
181extern void abort(void);
182
183void
184single(int a, int b) {
185#pragma omp single copyprivate(a) copyprivate(b)
186 {
187 a = b = 5;
188 }
189
190 if (a != b)
191 abort();
192}
193
194int parallel() {
195#pragma omp parallel
196 single(1, 2);
197
198 return 0;
199}