[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / single_copyprivate_messages.cpp
blob1dc508b01bd74b06fdd3e7ce1d8164cf0c072b35
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 void foo() {
8 struct S1; // expected-note 2 {{declared here}}
9 class S2 {
10 mutable int a;
12 public:
13 S2() : a(0) {}
14 S2 &operator=(S2 &s2) { return *this; }
16 class S3 {
17 int a;
19 public:
20 S3() : a(0) {}
21 S3 &operator=(S3 &s3) { return *this; }
23 class S4 {
24 int a;
25 S4();
26 S4 &operator=(const S4 &s4); // expected-note 3 {{implicitly declared private here}}
28 public:
29 S4(int v) : a(v) {}
31 class S5 {
32 int a;
33 S5() : a(0) {}
34 S5 &operator=(const S5 &s5) { return *this; } // expected-note 3 {{implicitly declared private here}}
36 public:
37 S5(int v) : a(v) {}
40 S2 k;
41 S3 h;
42 S4 l(3);
43 S5 m(4);
44 #pragma omp threadprivate(h, k, l, m)
46 template <class T, class C>
47 T tmain(T argc, C **argv) {
48 T i, z;
49 static T TA;
50 #pragma omp single copyprivate(z)
52 #pragma omp parallel
53 #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
54 #pragma omp parallel
55 #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
56 #pragma omp parallel
57 #pragma omp single copyprivate() // expected-error {{expected expression}}
58 #pragma omp parallel
59 #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
60 #pragma omp parallel
61 #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
62 #pragma omp parallel
63 #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
64 #pragma omp parallel
65 #pragma omp single copyprivate(l) // expected-error 2 {{'operator=' is a private member of 'S4'}}
66 #pragma omp parallel
67 #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
68 #pragma omp parallel
69 #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
70 #pragma omp parallel // expected-note {{implicitly determined as shared}}
71 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
72 #pragma omp parallel
73 #pragma omp single copyprivate(m) // expected-error 2 {{'operator=' is a private member of 'S5'}}
74 foo();
75 #pragma omp parallel private(i)
77 #pragma omp single copyprivate(i)
78 foo();
80 #pragma omp parallel shared(i) // expected-note {{defined as shared}}
82 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
83 foo();
85 #pragma omp parallel private(i)
86 #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
88 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
89 foo();
91 #pragma omp parallel private(i)
92 #pragma omp parallel // expected-note {{implicitly determined as shared}}
94 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
95 foo();
97 #pragma omp parallel
98 #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
99 foo();
100 #pragma omp parallel
101 #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
102 foo();
103 #pragma omp parallel private(TA)
105 #pragma omp single copyprivate(TA)
106 TA = 99;
109 return T();
112 void bar(S4 a[2], int n, int b[n]) {
113 #pragma omp single copyprivate(a, b)
114 foo();
117 namespace A {
118 double x;
119 #pragma omp threadprivate(x)
121 namespace B {
122 using A::x;
125 int main(int argc, char **argv) {
126 int i, z;
127 static int intA;
128 #pragma omp parallel
129 #pragma omp single copyprivate // expected-error {{expected '(' after 'copyprivate'}}
130 #pragma omp parallel
131 #pragma omp single copyprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
132 #pragma omp parallel
133 #pragma omp single copyprivate() // expected-error {{expected expression}}
134 #pragma omp parallel
135 #pragma omp single copyprivate(k // expected-error {{expected ')'}} expected-note {{to match this '('}}
136 #pragma omp parallel
137 #pragma omp single copyprivate(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
138 #pragma omp parallel
139 #pragma omp single copyprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
140 #pragma omp parallel
141 #pragma omp single copyprivate(l, B::x) // expected-error {{'operator=' is a private member of 'S4'}}
142 #pragma omp parallel
143 #pragma omp single copyprivate(S1) // expected-error {{'S1' does not refer to a value}}
144 #pragma omp parallel
145 #pragma omp single copyprivate(argv[1]) // expected-error {{expected variable name}}
146 #pragma omp parallel // expected-note {{implicitly determined as shared}}
147 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
148 #pragma omp parallel
149 #pragma omp single copyprivate(m) // expected-error {{'operator=' is a private member of 'S5'}}
150 foo();
151 #pragma omp parallel private(i, z)
153 #pragma omp single copyprivate(i, z)
154 foo();
156 #pragma omp parallel shared(i) // expected-note {{defined as shared}}
158 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
159 foo();
161 #pragma omp parallel private(i)
162 #pragma omp parallel default(shared) // expected-note {{implicitly determined as shared}}
164 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
165 foo();
167 #pragma omp parallel private(i)
168 #pragma omp parallel // expected-note {{implicitly determined as shared}}
170 #pragma omp single copyprivate(i) // expected-error {{copyprivate variable must be threadprivate or private in the enclosing context}}
171 foo();
173 #pragma omp parallel
174 #pragma omp single private(i) copyprivate(i) // expected-error {{private variable cannot be copyprivate}} expected-note {{defined as private}}
175 foo();
176 #pragma omp parallel
177 #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}}
178 foo();
179 #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}}
180 foo();
181 #pragma omp parallel private(intA)
183 #pragma omp single copyprivate(intA)
184 intA = 99;
187 return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}}
190 extern void abort(void);
192 void
193 single(int a, int b) {
194 #pragma omp single copyprivate(a) copyprivate(b)
196 a = b = 5;
199 if (a != b)
200 abort();
203 int parallel() {
204 #pragma omp parallel
205 single(1, 2);
207 return 0;