xref: /llvm-project/clang/test/OpenMP/teams_distribute_simd_messages.cpp (revision 0c6f2f629cc0017361310fa4c132090413a874db)
1 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -verify=expected,omp45 -std=c++11 %s -Wuninitialized
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -verify=expected,omp5,omp50 -std=c++11 %s -Wuninitialized
3 // RUN: %clang_cc1 -fopenmp -verify=expected,omp5,omp51 -std=c++11 %s -Wuninitialized
4 
5 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -verify=expected,omp45 -std=c++11 %s -Wuninitialized
6 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -verify=expected,omp5,omp50 -std=c++11 %s -Wuninitialized
7 // RUN: %clang_cc1 -fopenmp-simd -verify=expected,omp5,omp51 -std=c++11 %s -Wuninitialized
8 
xxx(int argc)9 void xxx(int argc) {
10   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
11 #pragma omp target
12 #pragma omp teams distribute simd
13   for (int i = 0; i < 10; ++i)
14     argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
15 }
16 
foo()17 void foo() {
18 }
19 
20 static int pvt;
21 #pragma omp threadprivate(pvt)
22 
23 #pragma omp teams distribute simd // expected-error {{unexpected OpenMP directive '#pragma omp teams distribute simd'}}
24 
main(int argc,char ** argv)25 int main(int argc, char **argv) {
26   #pragma omp target
27   #pragma omp teams distribute simd
28   f; // expected-error {{use of undeclared identifier 'f'}}
29 #pragma omp target
30 #pragma omp teams distribute simd { // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
31   for (int i = 0; i < argc; ++i)
32     foo();
33 #pragma omp target
34 #pragma omp teams distribute simd ( // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
35   for (int i = 0; i < argc; ++i)
36     foo();
37 #pragma omp target
38 #pragma omp teams distribute simd[ // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
39   for (int i = 0; i < argc; ++i)
40     foo();
41 #pragma omp target
42 #pragma omp teams distribute simd] // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
43   for (int i = 0; i < argc; ++i)
44     foo();
45 #pragma omp target
46 #pragma omp teams distribute simd) // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
47   for (int i = 0; i < argc; ++i)
48     foo();
49 #pragma omp target
50 #pragma omp teams distribute simd } // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
51   for (int i = 0; i < argc; ++i)
52     foo();
53 #pragma omp target
54 #pragma omp teams distribute simd
55   for (int i = 0; i < argc; ++i)
56     foo();
57 // expected-warning@+2 {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
58 #pragma omp target
59 #pragma omp teams distribute simd unknown()
60   for (int i = 0; i < argc; ++i)
61     foo();
62 L1:
63   for (int i = 0; i < argc; ++i)
64     foo();
65 #pragma omp target
66 #pragma omp teams distribute simd
67   for (int i = 0; i < argc; ++i)
68     foo();
69 #pragma omp target
70 #pragma omp teams distribute simd
71   for (int i = 0; i < argc; ++i) {
72     goto L1; // expected-error {{use of undeclared label 'L1'}}
73     argc++;
74   }
75 
76   for (int i = 0; i < 10; ++i) {
77     switch (argc) {
78     case (0):
79 #pragma omp target
80 #pragma omp teams distribute simd
81       for (int i = 0; i < argc; ++i) {
82         foo();
83         break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
84         continue;
85       }
86     default:
87       break;
88     }
89   }
90 #pragma omp target
91 #pragma omp teams distribute simd default(none) // expected-note {{explicit data sharing attribute requested here}}
92   for (int i = 0; i < 10; ++i)
93     ++argc; // expected-error {{ariable 'argc' must have explicitly specified data sharing attributes}}
94 
95   goto L2; // expected-error {{use of undeclared label 'L2'}}
96 #pragma omp target
97 #pragma omp teams distribute simd
98   for (int i = 0; i < argc; ++i)
99   L2:
100   foo();
101 #pragma omp target
102 #pragma omp teams distribute simd
103   for (int i = 0; i < argc; ++i) {
104     return 1; // expected-error {{cannot return from OpenMP region}}
105   }
106 
107   [[]] // expected-error {{an attribute list cannot appear here}}
108 #pragma omp target
109 #pragma omp teams distribute simd
110       for (int n = 0; n < 100; ++n) {
111   }
112 
113 #pragma omp target
114 #pragma omp teams distribute simd copyin(pvt) // expected-error {{unexpected OpenMP clause 'copyin' in directive '#pragma omp teams distribute simd'}}
115   for (int n = 0; n < 100; ++n) {}
116 
117   return 0;
118 }
119 
test_ordered()120 void test_ordered() {
121 #pragma omp target
122 #pragma omp teams distribute simd ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp teams distribute simd'}}
123   for (int i = 0; i < 16; ++i)
124     ;
125 }
126 
test_nontemporal()127 void test_nontemporal() {
128   int i;
129 #pragma omp target
130 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
131 #pragma omp teams distribute simd nontemporal(
132   for (i = 0; i < 16; ++i)
133     ;
134 #pragma omp target
135 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 2 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
136 #pragma omp teams distribute simd nontemporal(,
137   for (i = 0; i < 16; ++i)
138     ;
139 #pragma omp target
140 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 2 {{expected expression}}
141 #pragma omp teams distribute simd nontemporal(, )
142   for (i = 0; i < 16; ++i)
143     ;
144 #pragma omp target
145 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{expected expression}}
146 #pragma omp teams distribute simd nontemporal()
147   for (i = 0; i < 16; ++i)
148     ;
149 #pragma omp target
150 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{expected '(' for function-style cast or type construction}}
151 #pragma omp teams distribute simd nontemporal(int)
152   for (i = 0; i < 16; ++i)
153     ;
154 #pragma omp target
155 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} omp5-error@+1 {{expected variable name}}
156 #pragma omp teams distribute simd nontemporal(0)
157   for (i = 0; i < 16; ++i)
158     ;
159 #pragma omp target
160 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{use of undeclared identifier 'x'}}
161 #pragma omp teams distribute simd nontemporal(x)
162   for (i = 0; i < 16; ++i)
163     ;
164 #pragma omp target
165 // expected-error@+2 {{use of undeclared identifier 'x'}}
166 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{use of undeclared identifier 'y'}}
167 #pragma omp teams distribute simd nontemporal(x, y)
168   for (i = 0; i < 16; ++i)
169     ;
170 #pragma omp target
171 // expected-error@+3 {{use of undeclared identifier 'x'}}
172 // expected-error@+2 {{use of undeclared identifier 'y'}}
173 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{use of undeclared identifier 'z'}}
174 #pragma omp teams distribute simd nontemporal(x, y, z)
175   for (i = 0; i < 16; ++i)
176     ;
177 
178   int x, y;
179 #pragma omp target
180 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{expected ',' or ')' in 'nontemporal' clause}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
181 #pragma omp teams distribute simd nontemporal(x :)
182   for (i = 0; i < 16; ++i)
183     ;
184 #pragma omp target
185 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} expected-error@+1 {{expected ',' or ')' in 'nontemporal' clause}}
186 #pragma omp teams distribute simd nontemporal(x :, )
187   for (i = 0; i < 16; ++i)
188     ;
189 
190 #pragma omp target
191 // omp5-note@+2 {{defined as nontemporal}}
192 // omp45-error@+1 2 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} omp5-error@+1 {{a variable cannot appear in more than one nontemporal clause}}
193 #pragma omp teams distribute simd nontemporal(x) nontemporal(x)
194   for (i = 0; i < 16; ++i)
195     ;
196 
197 #pragma omp target
198 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}}
199 #pragma omp teams distribute simd private(x) nontemporal(x)
200   for (i = 0; i < 16; ++i)
201     ;
202 
203 #pragma omp target
204 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}}
205 #pragma omp teams distribute simd nontemporal(x) private(x)
206   for (i = 0; i < 16; ++i)
207     ;
208 
209 #pragma omp target
210 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}} expected-note@+1 {{to match this '('}} expected-error@+1 {{expected ',' or ')' in 'nontemporal' clause}} expected-error@+1 {{expected ')'}}
211 #pragma omp teams distribute simd nontemporal(x, y : 0)
212   for (i = 0; i < 16; ++i)
213     ;
214 
215 #pragma omp target
216 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}}
217 #pragma omp teams distribute simd nontemporal(x) lastprivate(x)
218   for (i = 0; i < 16; ++i)
219     ;
220 
221 #pragma omp target
222 // omp45-error@+1 {{unexpected OpenMP clause 'nontemporal' in directive '#pragma omp teams distribute simd'}}
223 #pragma omp teams distribute simd lastprivate(x) nontemporal(x)
224   for (i = 0; i < 16; ++i)
225     ;
226 #pragma omp target
227 #pragma omp teams distribute simd order // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} expected-error {{expected '(' after 'order'}}
228   for (int i = 0; i < 10; ++i)
229     ;
230 #pragma omp target
231 #pragma omp teams distribute simd order( // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp5-error {{expected 'concurrent' in OpenMP clause 'order'}}
232   for (int i = 0; i < 10; ++i)
233     ;
234 #pragma omp target
235 #pragma omp teams distribute simd order(none // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp5-error {{expected 'concurrent' in OpenMP clause 'order'}}
236   for (int i = 0; i < 10; ++i)
237     ;
238 #pragma omp target
239 #pragma omp teams distribute simd order(concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
240   for (int i = 0; i < 10; ++i)
241     ;
242 #pragma omp target
243 #pragma omp teams distribute simd order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}}
244   for (int i = 0; i < 10; ++i)
245     ;
246 #pragma omp target
247 #pragma omp teams distribute simd order(unconstrained:) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} omp5-error {{expected 'concurrent' in OpenMP clause 'order'}}
248   for (int i = 0; i < 10; ++i)
249     ;
250 #pragma omp target
251 #pragma omp teams distribute simd order(reproducible:concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
252   for (int i = 0; i < 10; ++i)
253     ;
254 #pragma omp target
255 #pragma omp teams distribute simd order(reproducible:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
256   for (int i = 0; i < 10; ++i)
257     ;
258 #pragma omp target
259 #pragma omp teams distribute simd order(unconstrained:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
260   for (int i = 0; i < 10; ++i)
261     ;
262 #pragma omp target
263 #pragma omp teams distribute simd order(concurrent) order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp teams distribute simd'}} omp51-error {{directive '#pragma omp teams distribute simd' cannot contain more than one 'order' clause}}
264   for (int i = 0; i < 10; ++i)
265     ;
266 }
267 
268