Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_firstprivate_messages.cpp
blob9b211297f5315d5e1d26cb40bcf2ab6baae604ad
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 void xxx(int argc) {
6 int fp, fp1; // expected-note {{initialize the variable 'fp' to silence this warning}} expected-note {{initialize the variable 'fp1' to silence this warning}}
7 #pragma omp target firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
8 for (int i = 0; i < 10; ++i)
9 ++fp1; // expected-warning {{variable 'fp1' is uninitialized when used here}}
12 typedef void **omp_allocator_handle_t;
13 extern const omp_allocator_handle_t omp_null_allocator;
14 extern const omp_allocator_handle_t omp_default_mem_alloc;
15 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
16 extern const omp_allocator_handle_t omp_const_mem_alloc;
17 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
18 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
19 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
20 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
21 extern const omp_allocator_handle_t omp_thread_mem_alloc;
23 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
24 extern S1 a;
25 class S2 {
26 mutable int a;
28 public:
29 S2() : a(0) {}
31 const S2 b;
32 const S2 ba[5];
33 class S3 {
34 int a;
36 public:
37 S3() : a(0) {}
39 const S3 ca[5];
40 class S4 {
41 int a;
42 S4();
44 public:
45 S4(int v) : a(v) {
46 #pragma omp target firstprivate(a) firstprivate(this->a)
47 for (int k = 0; k < v; ++k)
48 ++this->a;
51 class S5 {
52 int a;
53 S5() : a(0) {}
55 public:
56 S5(int v) : a(v) {}
57 S5 &operator=(S5 &s) {
58 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}}
59 for (int k = 0; k < s.a; ++k) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
60 ++s.a;
61 return *this;
65 template <typename T>
66 class S6 {
67 public:
68 T a;
70 S6() : a(0) {}
71 S6(T v) : a(v) {
72 #pragma omp target firstprivate(a) firstprivate(this->a)
73 for (int k = 0; k < v; ++k)
74 ++this->a;
76 S6 &operator=(S6 &s) {
77 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}}
78 for (int k = 0; k < s.a; ++k)
79 ++s.a;
80 return *this;
84 template <typename T>
85 class S7 : public T {
86 T a;
87 S7() : a(0) {}
89 public:
90 S7(T v) : a(v) {
91 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(T::a)
92 for (int k = 0; k < a.a; ++k)
93 ++this->a.a;
95 S7 &operator=(S7 &s) {
96 #pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) firstprivate(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
97 for (int k = 0; k < s.a.a; ++k)
98 ++s.a.a;
99 return *this;
103 S3 h;
104 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
106 template <class I, class C>
107 int foomain(I argc, C **argv) {
108 I e(4);
109 I g(5);
110 int i, z;
111 int &j = i;
112 #pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}}
114 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
116 #pragma omp target firstprivate() // expected-error {{expected expression}}
118 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
120 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
122 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
124 #pragma omp target firstprivate(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 '('}}
126 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
128 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
130 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
132 #pragma omp target firstprivate(e, g) allocate(omp_thread_mem_alloc: e) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target' directive}} expected-error {{allocator must be specified in the 'uses_allocators' clause}}
134 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
136 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
137 #pragma omp parallel
139 int v = 0;
140 int i;
142 #pragma omp parallel shared(i, z)
143 #pragma omp parallel firstprivate(i, z)
144 #pragma omp target firstprivate(j)
146 #pragma omp target firstprivate(i)
148 return 0;
151 void bar(S4 a[2]) {
152 #pragma omp parallel
153 #pragma omp target firstprivate(a)
157 namespace A {
158 double x;
159 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
161 namespace B {
162 using A::x;
165 int main(int argc, char **argv) {
166 S4 e(4);
167 S5 g(5);
168 S6<float> s6(0.0) , s6_0(1.0);
169 S7<S6<float> > s7(0.0) , s7_0(1.0);
170 int i, z;
171 int &j = i;
172 #pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}}
174 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
176 #pragma omp target firstprivate() // expected-error {{expected expression}}
178 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
180 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
182 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
184 #pragma omp target firstprivate(argc, z)
186 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
188 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
190 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
192 #pragma omp target firstprivate(e, g)
194 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
196 #pragma omp target firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
198 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
199 #pragma omp parallel
201 int i;
203 #pragma omp parallel shared(i)
204 #pragma omp parallel firstprivate(i)
205 #pragma omp target firstprivate(j)
207 #pragma omp target firstprivate(i)
209 static int si;
210 #pragma omp target firstprivate(si) // OK
212 #pragma omp target map(i) firstprivate(i) // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target' directive}}
214 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
215 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float>>::operator=' requested here}}
216 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}