Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / OpenMP / clause-validity01.f90
blobe641493a2ccc339abd103271815c3f0fa1f957cc
1 ! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2 use omp_lib
3 ! Check OpenMP clause validity for the following directives:
5 ! 2.5 PARALLEL construct
6 ! 2.7.1 Loop construct
7 ! ...
9 integer :: b = 128
10 integer :: z, c = 32
11 integer, parameter :: num = 16
12 real(8) :: arrayA(256), arrayB(512)
14 integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space
15 type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)]
16 integer(omp_allocator_handle_kind) :: xy_alloc
17 xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits)
19 arrayA = 1.414
20 arrayB = 3.14
21 N = 1024
23 ! 2.5 parallel-clause -> if-clause |
24 ! num-threads-clause |
25 ! default-clause |
26 ! private-clause |
27 ! firstprivate-clause |
28 ! shared-clause |
29 ! copyin-clause |
30 ! reduction-clause |
31 ! proc-bind-clause |
32 ! allocate-clause
34 !$omp parallel
35 do i = 1, N
36 a = 3.14
37 enddo
38 !$omp end parallel
40 !$omp parallel private(b) allocate(b)
41 do i = 1, N
42 a = 3.14
43 enddo
44 !$omp end parallel
46 !$omp parallel private(c, b) allocate(omp_default_mem_space : b, c)
47 do i = 1, N
48 a = 3.14
49 enddo
50 !$omp end parallel
52 !$omp parallel allocate(b) allocate(c) private(b, c)
53 do i = 1, N
54 a = 3.14
55 enddo
56 !$omp end parallel
58 !$omp parallel allocate(xy_alloc :b) private(b)
59 do i = 1, N
60 a = 3.14
61 enddo
62 !$omp end parallel
64 !$omp task private(b) allocate(b)
65 do i = 1, N
66 z = 2
67 end do
68 !$omp end task
70 !$omp teams private(b) allocate(b)
71 do i = 1, N
72 z = 2
73 end do
74 !$omp end teams
76 !$omp target private(b) allocate(b)
77 do i = 1, N
78 z = 2
79 end do
80 !$omp end target
82 !ERROR: ALLOCATE clause is not allowed on the TARGET DATA directive
83 !$omp target data map(from: b) allocate(b)
84 do i = 1, N
85 z = 2
86 enddo
87 !$omp end target data
89 !ERROR: SCHEDULE clause is not allowed on the PARALLEL directive
90 !$omp parallel schedule(static)
91 do i = 1, N
92 a = 3.14
93 enddo
94 !$omp end parallel
96 !ERROR: COLLAPSE clause is not allowed on the PARALLEL directive
97 !$omp parallel collapse(2)
98 do i = 1, N
99 do j = 1, N
100 a = 3.14
101 enddo
102 enddo
103 !$omp end parallel
105 !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression
106 !$omp do collapse(-1)
107 do i = 1, N
108 do j = 1, N
109 a = 3.14
110 enddo
111 enddo
112 !$omp end do
114 a = 1.0
115 !$omp parallel firstprivate(a)
116 do i = 1, N
117 a = 3.14
118 enddo
119 !ERROR: NUM_THREADS clause is not allowed on the END PARALLEL directive
120 !$omp end parallel num_threads(4)
122 !ERROR: LASTPRIVATE clause is not allowed on the PARALLEL directive
123 !ERROR: NUM_TASKS clause is not allowed on the PARALLEL directive
124 !ERROR: INBRANCH clause is not allowed on the PARALLEL directive
125 !$omp parallel lastprivate(a) NUM_TASKS(4) inbranch
126 do i = 1, N
127 a = 3.14
128 enddo
129 !$omp end parallel
131 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL directive
132 !$omp parallel num_threads(2) num_threads(4)
133 do i = 1, N
134 a = 3.14
135 enddo
136 !$omp end parallel
138 !ERROR: The parameter of the NUM_THREADS clause must be a positive integer expression
139 !$omp parallel num_threads(1-4)
140 do i = 1, N
141 a = 3.14
142 enddo
143 !ERROR: NOWAIT clause is not allowed on the END PARALLEL directive
144 !$omp end parallel nowait
146 !$omp parallel num_threads(num-10)
147 do i = 1, N
148 a = 3.14
149 enddo
150 !$omp end parallel
152 !$omp parallel num_threads(b+1)
153 do i = 1, N
154 a = 3.14
155 enddo
156 !$omp end parallel
158 !$omp parallel
159 do i = 1, N
160 enddo
161 !ERROR: Unmatched END TARGET directive
162 !$omp end target
164 ! OMP 5.0 - 2.6 Restriction point 1
165 outofparallel: do k =1, 10
166 !$omp parallel
167 !$omp do
168 outer: do i=0, 10
169 inner: do j=1, 10
170 exit
171 exit outer
172 !ERROR: EXIT to construct 'outofparallel' outside of PARALLEL construct is not allowed
173 !ERROR: EXIT to construct 'outofparallel' outside of DO construct is not allowed
174 exit outofparallel
175 end do inner
176 end do outer
177 !$omp end do
178 !$omp end parallel
179 end do outofparallel
181 ! 2.7.1 do-clause -> private-clause |
182 ! firstprivate-clause |
183 ! lastprivate-clause |
184 ! linear-clause |
185 ! reduction-clause |
186 ! schedule-clause |
187 ! collapse-clause |
188 ! ordered-clause
190 !ERROR: When SCHEDULE clause has AUTO specified, it must not have chunk size specified
191 !ERROR: At most one SCHEDULE clause can appear on the DO directive
192 !ERROR: When SCHEDULE clause has RUNTIME specified, it must not have chunk size specified
193 !$omp do schedule(auto, 2) schedule(runtime, 2)
194 do i = 1, N
195 a = 3.14
196 enddo
198 !ERROR: A modifier may not be specified in a LINEAR clause on the DO directive
199 !$omp do linear(ref(b))
200 do i = 1, N
201 a = 3.14
202 enddo
204 !ERROR: The NONMONOTONIC modifier can only be specified with SCHEDULE(DYNAMIC) or SCHEDULE(GUIDED)
205 !ERROR: The NONMONOTONIC modifier cannot be specified if an ORDERED clause is specified
206 !$omp do schedule(NONMONOTONIC:static) ordered
207 do i = 1, N
208 a = 3.14
209 enddo
211 !$omp do schedule(simd, monotonic:dynamic)
212 do i = 1, N
213 a = 3.14
214 enddo
216 !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
217 !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
218 !$omp do ordered(1-1) private(b) linear(b) linear(a)
219 do i = 1, N
220 a = 3.14
221 enddo
223 !ERROR: The parameter of the ORDERED clause must be greater than or equal to the parameter of the COLLAPSE clause
224 !$omp do collapse(num-14) ordered(1)
225 do i = 1, N
226 do j = 1, N
227 do k = 1, N
228 a = 3.14
229 enddo
230 enddo
231 enddo
233 !$omp parallel do simd if(parallel:a>1.)
234 do i = 1, N
235 enddo
236 !$omp end parallel do simd
238 !ERROR: Unmatched directive name modifier TARGET on the IF clause
239 !$omp parallel do if(target:a>1.)
240 do i = 1, N
241 enddo
242 !ERROR: Unmatched END SIMD directive
243 !$omp end simd
245 ! 2.7.2 sections-clause -> private-clause |
246 ! firstprivate-clause |
247 ! lastprivate-clause |
248 ! reduction-clause
250 !$omp parallel
251 !$omp sections
252 !$omp section
253 a = 0.0
254 !$omp section
255 b = 1
256 !$omp end sections nowait
257 !$omp end parallel
259 !$omp parallel
260 !$omp sections
261 !$omp section
262 a = 0.0
263 !ERROR: Unmatched END PARALLEL SECTIONS directive
264 !$omp end parallel sections
265 !$omp end parallel
267 !$omp parallel
268 !$omp sections
269 a = 0.0
270 b = 1
271 !$omp section
272 c = 1
273 d = 2
274 !ERROR: NUM_THREADS clause is not allowed on the END SECTIONS directive
275 !$omp end sections num_threads(4)
277 !$omp parallel
278 !$omp sections
279 b = 1
280 !$omp section
281 c = 1
282 d = 2
283 !ERROR: At most one NOWAIT clause can appear on the END SECTIONS directive
284 !$omp end sections nowait nowait
285 !$omp end parallel
287 !$omp end parallel
289 ! 2.11.2 parallel-sections-clause -> parallel-clause |
290 ! sections-clause
292 !$omp parallel sections num_threads(4) private(b) lastprivate(d)
293 a = 0.0
294 !$omp section
295 b = 1
296 c = 2
297 !$omp section
298 d = 3
299 !$omp end parallel sections
301 !ERROR: At most one NUM_THREADS clause can appear on the PARALLEL SECTIONS directive
302 !$omp parallel sections num_threads(1) num_threads(4)
303 a = 0.0
304 !ERROR: Unmatched END SECTIONS directive
305 !$omp end sections
307 !$omp parallel sections
308 !ERROR: NOWAIT clause is not allowed on the END PARALLEL SECTIONS directive
309 !$omp end parallel sections nowait
311 ! 2.7.3 single-clause -> private-clause |
312 ! firstprivate-clause
313 ! end-single-clause -> copyprivate-clause |
314 ! nowait-clause
316 !$omp parallel
317 b = 1
318 !ERROR: LASTPRIVATE clause is not allowed on the SINGLE directive
319 !$omp single private(a) lastprivate(c)
320 a = 3.14
321 !ERROR: Clause NOWAIT is not allowed if clause COPYPRIVATE appears on the END SINGLE directive
322 !ERROR: COPYPRIVATE variable 'a' may not appear on a PRIVATE or FIRSTPRIVATE clause on a SINGLE construct
323 !ERROR: At most one NOWAIT clause can appear on the END SINGLE directive
324 !$omp end single copyprivate(a) nowait nowait
325 c = 2
326 !$omp end parallel
328 ! 2.7.4 workshare
330 !$omp parallel
331 !$omp workshare
332 a = 1.0
333 !$omp end workshare nowait
334 !ERROR: NUM_THREADS clause is not allowed on the WORKSHARE directive
335 !$omp workshare num_threads(4)
336 a = 1.0
337 !ERROR: COPYPRIVATE clause is not allowed on the END WORKSHARE directive
338 !$omp end workshare nowait copyprivate(a)
339 !$omp end parallel
341 ! 2.8.1 simd-clause -> safelen-clause |
342 ! simdlen-clause |
343 ! linear-clause |
344 ! aligned-clause |
345 ! private-clause |
346 ! lastprivate-clause |
347 ! reduction-clause |
348 ! collapse-clause
350 a = 0.0
351 !ERROR: TASK_REDUCTION clause is not allowed on the SIMD directive
352 !$omp simd private(b) reduction(+:a) task_reduction(+:a)
353 do i = 1, N
354 a = a + b + 3.14
355 enddo
357 !ERROR: At most one SAFELEN clause can appear on the SIMD directive
358 !$omp simd safelen(1) safelen(2)
359 do i = 1, N
360 a = 3.14
361 enddo
363 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
364 !$omp simd simdlen(-1)
365 do i = 1, N
366 a = 3.14
367 enddo
369 !ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
370 !$omp simd aligned(b:-2)
371 do i = 1, N
372 a = 3.14
373 enddo
375 !$omp parallel
376 !ERROR: The parameter of the SIMDLEN clause must be less than or equal to the parameter of the SAFELEN clause
377 !$omp simd safelen(1+1) simdlen(1+2)
378 do i = 1, N
379 a = 3.14
380 enddo
381 !$omp end parallel
383 ! 2.11.1 parallel-do-clause -> parallel-clause |
384 ! do-clause
386 !ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive
387 !ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive
388 !$omp parallel do proc_bind(master) proc_bind(close) linear(val(b))
389 do i = 1, N
390 a = 3.14
391 enddo
393 ! 2.8.3 do-simd-clause -> do-clause |
394 ! simd-clause
396 !$omp parallel
397 !ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive
398 !ERROR: NOGROUP clause is not allowed on the DO SIMD directive
399 !$omp do simd ordered(2) NOGROUP
400 do i = 1, N
401 do j = 1, N
402 a = 3.14
403 enddo
404 enddo
405 !$omp end parallel
407 ! 2.11.4 parallel-do-simd-clause -> parallel-clause |
408 ! do-simd-clause
410 !$omp parallel do simd collapse(2) safelen(2) &
411 !$omp & simdlen(1) private(c) firstprivate(a) proc_bind(spread)
412 do i = 1, N
413 do j = 1, N
414 a = 3.14
415 enddo
416 enddo
418 ! 2.9.2 taskloop -> TASKLOOP [taskloop-clause[ [,] taskloop-clause]...]
419 ! taskloop-clause -> if-clause |
420 ! shared-clause |
421 ! private-clause |
422 ! firstprivate-clause |
423 ! lastprivate-clause |
424 ! default-clause |
425 ! grainsize-clause |
426 ! num-tasks-clause |
427 ! collapse-clause |
428 ! final-clause |
429 ! priority-clause |
430 ! untied-clause |
431 ! mergeable-clause |
432 ! nogroup-clause
434 !$omp taskloop
435 do i = 1, N
436 a = 3.14
437 enddo
439 !ERROR: SCHEDULE clause is not allowed on the TASKLOOP directive
440 !$omp taskloop schedule(static)
441 do i = 1, N
442 a = 3.14
443 enddo
445 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP directive
446 !$omp taskloop num_tasks(3) grainsize(2)
447 do i = 1,N
448 a = 3.14
449 enddo
451 !ERROR: At most one NUM_TASKS clause can appear on the TASKLOOP directive
452 !ERROR: TASK_REDUCTION clause is not allowed on the TASKLOOP directive
453 !$omp taskloop num_tasks(3) num_tasks(2) task_reduction(*:a)
454 do i = 1,N
455 a = 3.14
456 enddo
458 ! 2.13.1 master
460 !$omp parallel
461 !$omp master
462 a=3.14
463 !$omp end master
464 !$omp end parallel
466 !$omp parallel
467 !ERROR: NUM_THREADS clause is not allowed on the MASTER directive
468 !$omp master num_threads(4)
469 a=3.14
470 !$omp end master
471 !$omp end parallel
473 ! Standalone Directives (basic)
475 !$omp taskyield
476 !$omp barrier
477 !$omp taskwait
478 !$omp taskwait depend(source)
479 ! !$omp taskwait depend(sink:i-1)
480 ! !$omp target enter data map(to:arrayA) map(alloc:arrayB)
481 ! !$omp target update from(arrayA) to(arrayB)
482 ! !$omp target exit data map(from:arrayA) map(delete:arrayB)
483 !$omp flush (c)
484 !$omp flush acq_rel
485 !$omp flush release
486 !$omp flush acquire
487 !ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
488 !$omp flush release (c)
489 !ERROR: SEQ_CST clause is not allowed on the FLUSH directive
490 !$omp flush seq_cst
491 !ERROR: RELAXED clause is not allowed on the FLUSH directive
492 !$omp flush relaxed
494 ! 2.13.2 critical Construct
496 ! !$omp critical (first)
497 a = 3.14
498 ! !$omp end critical (first)
500 ! 2.9.1 task-clause -> if-clause |
501 ! final-clause |
502 ! untied-clause |
503 ! default-clause |
504 ! mergeable-clause |
505 ! private-clause |
506 ! firstprivate-clause |
507 ! shared-clause |
508 ! depend-clause |
509 ! priority-clause
511 !$omp task shared(a) default(none) if(task:a > 1.)
512 a = 1.
513 !$omp end task
515 !ERROR: Unmatched directive name modifier TASKLOOP on the IF clause
516 !$omp task private(a) if(taskloop:a.eq.1)
517 a = 1.
518 !$omp end task
520 !ERROR: LASTPRIVATE clause is not allowed on the TASK directive
521 !ERROR: At most one FINAL clause can appear on the TASK directive
522 !$omp task lastprivate(b) final(a.GE.1) final(.false.)
523 b = 1
524 !$omp end task
526 !ERROR: The parameter of the PRIORITY clause must be a positive integer expression
527 !$omp task priority(-1) firstprivate(a) mergeable
528 a = 3.14
529 !$omp end task
531 ! 2.9.3 taskloop-simd-clause -> taskloop-clause |
532 ! simd-clause
534 !$omp taskloop simd
535 do i = 1, N
536 a = 3.14
537 enddo
538 !$omp end taskloop simd
540 !$omp taskloop simd reduction(+:a)
541 do i = 1, N
542 a = a + 3.14
543 enddo
544 !ERROR: Unmatched END TASKLOOP directive
545 !$omp end taskloop
547 !ERROR: GRAINSIZE and NUM_TASKS clauses are mutually exclusive and may not appear on the same TASKLOOP SIMD directive
548 !$omp taskloop simd num_tasks(3) grainsize(2)
549 do i = 1,N
550 a = 3.14
551 enddo
553 !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
554 !ERROR: The parameter of the ALIGNED clause must be a constant positive integer expression
555 !$omp taskloop simd simdlen(-1) aligned(a:-2)
556 do i = 1, N
557 a = 3.14
558 enddo
560 !$omp target enter data map(alloc:A) device(0)
561 !$omp target exit data map(delete:A) device(0)
563 end program