1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
4
xxx(int argc)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}}
10 }
11
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;
22
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;
27
28 public:
S2()29 S2() : a(0) {}
30 };
31 const S2 b;
32 const S2 ba[5];
33 class S3 {
34 int a;
35
36 public:
S3()37 S3() : a(0) {}
38 };
39 const S3 ca[5];
40 class S4 {
41 int a;
42 S4();
43
44 public:
S4(int v)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;
49 }
50 };
51 class S5 {
52 int a;
S5()53 S5() : a(0) {}
54
55 public:
S5(int v)56 S5(int v) : a(v) {}
operator =(S5 & s)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;
62 }
63 };
64
65 template <typename T>
66 class S6 {
67 public:
68 T a;
69
S6()70 S6() : a(0) {}
S6(T v)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;
75 }
operator =(S6 & s)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;
81 }
82 };
83
84 template <typename T>
85 class S7 : public T {
86 T a;
S7()87 S7() : a(0) {}
88
89 public:
S7(T v)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;
94 }
operator =(S7 & s)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;
100 }
101 };
102
103 S3 h;
104 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
105
106 template <class I, class C>
foomain(I argc,C ** argv)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'}}
113 {}
114 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
115 {}
116 #pragma omp target firstprivate() // expected-error {{expected expression}}
117 {}
118 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
119 {}
120 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
121 {}
122 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
123 {}
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 '('}}
125 {}
126 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
127 {}
128 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
129 {}
130 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
131 {}
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}}
133 {}
134 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
135 {}
136 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
137 #pragma omp parallel
138 {
139 int v = 0;
140 int i;
141 }
142 #pragma omp parallel shared(i, z)
143 #pragma omp parallel firstprivate(i, z)
144 #pragma omp target firstprivate(j)
145 {}
146 #pragma omp target firstprivate(i)
147 {}
148 return 0;
149 }
150
bar(S4 a[2])151 void bar(S4 a[2]) {
152 #pragma omp parallel
153 #pragma omp target firstprivate(a)
154 {}
155 }
156
157 namespace A {
158 double x;
159 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
160 }
161 namespace B {
162 using A::x;
163 }
164
main(int argc,char ** argv)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'}}
173 {}
174 #pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
175 {}
176 #pragma omp target firstprivate() // expected-error {{expected expression}}
177 {}
178 #pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
179 {}
180 #pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181 {}
182 #pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
183 {}
184 #pragma omp target firstprivate(argc, z)
185 {}
186 #pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
187 {}
188 #pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
189 {}
190 #pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
191 {}
192 #pragma omp target firstprivate(e, g)
193 {}
194 #pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
195 {}
196 #pragma omp target firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
197 {}
198 #pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
199 #pragma omp parallel
200 {
201 int i;
202 }
203 #pragma omp parallel shared(i)
204 #pragma omp parallel firstprivate(i)
205 #pragma omp target firstprivate(j)
206 {}
207 #pragma omp target firstprivate(i)
208 {}
209 static int si;
210 #pragma omp target firstprivate(si) // OK
211 {}
212 #pragma omp target map(i) firstprivate(i) // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target' directive}}
213 {}
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}}
217 }
218
219