Debian Codegraph @

gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90

raw
1 ! { dg-do compile }
2 ! PR fortran/107067
3
4 program metadirectives
5 implicit none
6 logical :: UseDevice
7 integer :: n, v
8
9 !$OMP begin metadirective &
10 !$OMP when ( user = { condition ( UseDevice ) } &
11 !$OMP : nothing ) &
12 !$OMP default ( parallel ) ! { dg-error "Variants in a metadirective at .1. have different associations" }
13 block
14 call foo()
15 end block
16 call bar() ! { dg-error "Expected OMP END METADIRECTIVE" }
17 !$omp end metadirective ! { dg-error "Unexpected ..OMP END METADIRECTIVE statement" }
18
19 ! It's a quirk of the implementation that gfortran thinks the metadirective
20 ! ends where the *last* variant ends. If we reverse the order of the
21 ! variants from the previous case, the "unexpected OMP END METADIRECTIVE"
22 ! error disappears because the "nothing" variant eats it where the
23 ! "parallel" directive doesn't.
24
25 !$OMP begin metadirective &
26 !$OMP when ( user = { condition ( UseDevice ) } &
27 !$OMP : parallel ) &
28 !$OMP default ( nothing ) ! { dg-error "Variants in a metadirective at .1. have different associations" }
29 block
30 call foo()
31 end block
32 call bar() ! { dg-error "Expected OMP END METADIRECTIVE" }
33 !$omp end metadirective
34
35 !$OMP begin metadirective &
36 !$OMP when ( user = { condition ( UseDevice ) } &
37 !$OMP : nothing ) &
38 !$OMP default ( parallel ) ! { dg-error "Variants in a metadirective at .1. have different associations" }
39 block
40 call bar()
41 end block
42 block ! { dg-error "Expected OMP END METADIRECTIVE" }
43 call foo()
44 end block
45 !$omp end metadirective ! { dg-error "Unexpected ..OMP END METADIRECTIVE statement" }
46
47 ! This one depends on the locus comparison and not just the statement
48 ! code comparison to diagnose the "different associations" error, since
49 ! there are two call statements involved.
50 !$OMP begin metadirective &
51 !$OMP when ( user = { condition ( UseDevice ) } &
52 !$OMP : nothing ) &
53 !$OMP default ( parallel ) ! { dg-error "Variants in a metadirective at .1. have different associations" }
54 block
55 call foo()
56 end block
57 call bar() ! { dg-error "Expected OMP END METADIRECTIVE" }
58 !$omp end metadirective ! { dg-error "Unexpected ..OMP END METADIRECTIVE statement" }
59 call baz()
60
61 ! The "nothing" directive in a non-begin/end metadirective only applies to a
62 ! a single statement or block, while "atomic capture" permits multiple
63 ! assignment statements.
64 !$OMP metadirective &
65 !$OMP when ( user = { condition ( UseDevice ) } &
66 !$OMP : nothing ) &
67 !$OMP default (atomic capture) ! { dg-error "Variants in a metadirective at .1. have different associations" }
68 n = n + 1; v = n
69
70 ! Reverse order of the above.
71 !$OMP metadirective &
72 !$OMP when ( user = { condition ( UseDevice ) } &
73 !$OMP : atomic capture ) &
74 !$OMP default ( nothing ) ! { dg-error "Variants in a metadirective at .1. have different associations" }
75 n = n + 1; v = n
76
77 ! This one is correct because both variants are properly terminated
78 ! by the "end metadirective".
79 !$OMP begin metadirective &
80 !$OMP when ( user = { condition ( UseDevice ) } &
81 !$OMP : nothing ) &
82 !$OMP default (atomic capture)
83 n = n + 1; v = n
84 !$omp end metadirective
85
86 end program
87
88