Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_private_messages.cpp
blob7ee0c8cffb9c8b6550686377b67515d0bf2f1997
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 #pragma omp requires dynamic_allocators
6 typedef void **omp_allocator_handle_t;
7 extern const omp_allocator_handle_t omp_null_allocator;
8 extern const omp_allocator_handle_t omp_default_mem_alloc;
9 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
10 extern const omp_allocator_handle_t omp_const_mem_alloc;
11 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
12 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
13 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
14 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
15 extern const omp_allocator_handle_t omp_thread_mem_alloc;
17 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
18 extern S1 a;
19 class S2 {
20 mutable int a;
22 public:
23 S2() : a(0) {}
25 const S2 b;
26 const S2 ba[5];
27 class S3 {
28 int a;
30 public:
31 S3() : a(0) {}
33 const S3 ca[5];
34 class S4 {
35 int a;
36 S4(); // expected-note {{implicitly declared private here}}
38 public:
39 S4(int v) : a(v) {
40 #pragma omp target private(a) private(this->a)
41 for (int k = 0; k < v; ++k)
42 ++this->a;
45 class S5 {
46 int a;
47 S5() : a(0) {} // expected-note {{implicitly declared private here}}
49 public:
50 S5(int v) : a(v) {}
51 S5 &operator=(S5 &s) {
52 #pragma omp target private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
53 for (int k = 0; k < s.a; ++k) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
54 ++s.a;
55 return *this;
59 template <typename T>
60 class S6 {
61 public:
62 T a;
64 S6() : a(0) {}
65 S6(T v) : a(v) {
66 #pragma omp target private(a) private(this->a) allocate(omp_thread_mem_alloc: a) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target' directive}}
67 for (int k = 0; k < v; ++k)
68 ++this->a;
70 S6 &operator=(S6 &s) {
71 #pragma omp target private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
72 for (int k = 0; k < s.a; ++k)
73 ++s.a;
74 return *this;
78 template <typename T>
79 class S7 : public T {
80 T a;
81 S7() : a(0) {}
83 public:
84 S7(T v) : a(v) {
85 #pragma omp target private(a) private(this->a) private(T::a)
86 for (int k = 0; k < a.a; ++k)
87 ++this->a.a;
89 S7 &operator=(S7 &s) {
90 #pragma omp target private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
91 for (int k = 0; k < s.a.a; ++k)
92 ++s.a.a;
93 return *this;
97 S3 h;
98 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
100 template <class I, class C>
101 int foomain(I argc, C **argv) {
102 I e(4);
103 I g(5);
104 int i;
105 int &j = i;
106 #pragma omp target private // expected-error {{expected '(' after 'private'}}
108 #pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
110 #pragma omp target private() // expected-error {{expected expression}}
112 #pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
114 #pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
116 #pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
118 #pragma omp target 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 '('}}
120 #pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}}
122 #pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
124 #pragma omp target private(argv[1]) // expected-error {{expected variable name}}
126 #pragma omp target private(e, g)
128 #pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
130 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
131 #pragma omp parallel
133 int v = 0;
134 int i;
136 #pragma omp parallel shared(i)
137 #pragma omp parallel private(i)
138 #pragma omp target private(j)
140 #pragma omp target private(i)
142 return 0;
145 void bar(S4 a[2]) {
146 #pragma omp parallel
147 #pragma omp target private(a)
151 namespace A {
152 double x;
153 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
155 namespace B {
156 using A::x;
159 int main(int argc, char **argv) {
160 S4 e(4);
161 S5 g(5);
162 S6<float> s6(0.0) , s6_0(1.0); // expected-note {{in instantiation of member function 'S6<float>::S6' requested here}}
163 S7<S6<float> > s7(0.0) , s7_0(1.0);
164 int i;
165 int &j = i;
166 #pragma omp target private // expected-error {{expected '(' after 'private'}}
168 #pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
170 #pragma omp target private() // expected-error {{expected expression}}
172 #pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
174 #pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
176 #pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
178 #pragma omp target private(argc)
180 #pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}}
182 #pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
184 #pragma omp target private(argv[1]) // expected-error {{expected variable name}}
186 #pragma omp target private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
188 #pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
190 #pragma omp target private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
192 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
193 #pragma omp parallel
195 int i;
197 #pragma omp parallel shared(i)
198 #pragma omp parallel private(i)
199 #pragma omp target private(j)
201 #pragma omp target private(i)
203 static int si;
204 #pragma omp target private(si) // OK
206 #pragma omp target map(i) private(i) // expected-error {{private variable cannot be in a map clause in '#pragma omp target' directive}}
208 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
209 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float>>::operator=' requested here}}
210 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}