[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_parallel_private_messages.cpp
blob44bf0b3512a28d77e9b005730603b94e34fcdc45
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 typedef void **omp_allocator_handle_t;
6 extern const omp_allocator_handle_t omp_null_allocator;
7 extern const omp_allocator_handle_t omp_default_mem_alloc;
8 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
9 extern const omp_allocator_handle_t omp_const_mem_alloc;
10 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
11 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
12 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
13 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
14 extern const omp_allocator_handle_t omp_thread_mem_alloc;
16 void foo() {
19 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} expected-note 1 {{forward declaration of 'S1'}} expected-note {{forward declaration of 'S1'}}
20 extern S1 a;
21 class S2 {
22 mutable int a;
24 public:
25 S2() : a(0) {}
26 static float S2s; // expected-note {{static data member is predetermined as shared}} expected-note 1 {{static data member is predetermined as shared}}
28 const S2 b;
29 const S2 ba[5];
30 class S3 {
31 int a;
33 public:
34 S3() : a(0) {}
36 const S3 c; // expected-note 2 {{'c' defined here}}
37 const S3 ca[5]; // expected-note 2 {{'ca' defined here}}
38 extern const int f; // expected-note 2 {{'f' declared here}}
40 int threadvar;
41 #pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}} expected-note 1 {{defined as threadprivate or thread local}}
43 class S4 {
44 int a;
45 S4(); // expected-note {{implicitly declared private here}} expected-note 1 {{implicitly declared private here}}
47 public:
48 S4(int v) : a(v) {}
50 class S5 {
51 int a;
52 S5() : a(0) {} // expected-note {{implicitly declared private here}} expected-note 1 {{implicitly declared private here}}
54 public:
55 S5(int v) : a(v) {}
57 namespace A {
58 double x;
59 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} expected-note 1 {{defined as threadprivate or thread local}} expected-note 2 {{defined as threadprivate or thread local}}
61 namespace B {
62 using A::x;
65 S3 h;
66 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
68 template <class I, class C, class D, class E>
69 int foomain(I argc, C **argv) {
70 const I d = 5; // expected-note {{'d' defined here}}
71 const I da[5] = { 0 }; // expected-note {{'da' defined here}}
72 D e(4);
73 E g[] = {5, 6};
74 I i;
75 I &j = i;
76 #pragma omp target parallel private // expected-error {{expected '(' after 'private'}}
78 #pragma omp target parallel private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
80 #pragma omp target parallel private() // expected-error {{expected expression}}
82 #pragma omp target parallel private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
84 #pragma omp target parallel private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
86 #pragma omp target parallel private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
88 #pragma omp target parallel private(argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}
90 #pragma omp target parallel private(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
92 #pragma omp target parallel private(S1) // expected-error {{'S1' does not refer to a value}}
94 #pragma omp target parallel private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
96 #pragma omp target parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be private}} expected-error 2 {{const-qualified variable cannot be private}}
98 #pragma omp target parallel private(argv[1]) // expected-error {{expected variable name}}
100 #pragma omp target parallel allocate(omp_thread_mem_alloc: ba) private(ba) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target parallel' directive}} expected-error {{allocator must be specified in the 'uses_allocators' clause}}
102 #pragma omp target parallel private(ca) // expected-error {{const-qualified variable without mutable fields cannot be private}}
104 #pragma omp target parallel private(da) // expected-error {{const-qualified variable cannot be private}}
106 #pragma omp target parallel private(S2::S2s) // expected-error {{shared variable cannot be private}}
108 #pragma omp target parallel private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
110 #pragma omp target parallel private(threadvar, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
112 #pragma omp target parallel shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}}
113 foo();
114 #pragma omp target parallel firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}}
115 foo();
116 #pragma omp target parallel private(i)
118 #pragma omp target parallel private(j)
119 foo();
120 #pragma omp parallel firstprivate(i)
121 for (int k = 0; k < 10; ++k) {
122 #pragma omp target parallel private(i)
123 foo();
125 static int m;
126 #pragma omp target parallel private(m) // OK
127 foo();
128 #pragma omp target parallel private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
130 #pragma omp target parallel private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
131 #pragma omp parallel
133 int v = 0;
134 int i;
136 #pragma omp target parallel shared(i)
138 #pragma omp target parallel private(i)
140 #pragma omp target parallel private(j)
142 #pragma omp target parallel private(i)
144 static int si;
145 #pragma omp target parallel private(si) // OK
147 return 0;
150 void bar(S4 a[2]) {
151 #pragma omp parallel
152 #pragma omp target parallel private(a)
156 int main(int argc, char **argv) {
157 const int d = 5; // expected-note {{'d' defined here}}
158 const int da[5] = { 0 }; // expected-note {{'da' defined here}}
159 S4 e(4);
160 S5 g[] = {5, 6};
161 int i;
162 int &j = i;
163 #pragma omp target parallel private // expected-error {{expected '(' after 'private'}}
165 #pragma omp target parallel private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
167 #pragma omp target parallel private() // expected-error {{expected expression}}
169 #pragma omp target parallel private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
171 #pragma omp target parallel private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
173 #pragma omp target parallel private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
175 #pragma omp target parallel private(argc argv) // expected-error {{expected ',' or ')' in 'private' clause}}
177 #pragma omp target parallel private(argc)
179 #pragma omp target parallel private(S1) // expected-error {{'S1' does not refer to a value}}
181 #pragma omp target parallel private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
183 #pragma omp target parallel private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be private}} expected-error 2 {{const-qualified variable cannot be private}}
185 #pragma omp target parallel private(argv[1]) // expected-error {{expected variable name}}
187 #pragma omp target parallel private(ba)
189 #pragma omp target parallel private(ca) // expected-error {{const-qualified variable without mutable fields cannot be private}}
191 #pragma omp target parallel private(da) // expected-error {{const-qualified variable cannot be private}}
193 #pragma omp target parallel private(S2::S2s) // expected-error {{shared variable cannot be private}}
195 #pragma omp target parallel private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
197 #pragma omp target parallel private(threadvar, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
199 #pragma omp target parallel shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}}
200 foo();
201 #pragma omp target parallel firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}}
202 foo();
203 #pragma omp target parallel private(i)
205 #pragma omp target parallel private(j)
206 foo();
207 #pragma omp parallel firstprivate(i)
208 for (int k = 0; k < 10; ++k) {
209 #pragma omp target parallel private(i)
210 foo();
212 static int m;
213 #pragma omp target parallel private(m) // OK
214 foo();
215 #pragma omp target parallel private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
217 #pragma omp target parallel private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
218 #pragma omp parallel
220 int i;
222 #pragma omp target parallel shared(i)
224 #pragma omp target parallel private(i)
226 #pragma omp target parallel private(j)
228 #pragma omp target parallel private(i)
230 static int si;
231 #pragma omp target parallel private(si) // OK
233 return foomain<int, char, S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char, S4, S5>' requested here}}