[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / flang / test / Semantics / OpenACC / acc-branch.f90
blob06c3b4da92921ab36238090b3e28a70915999284
1 ! RUN: %python %S/../test_errors.py %s %flang -fopenacc
3 ! Check OpenACC restruction in branch in and out of some construct
5 program openacc_clause_validity
7 implicit none
9 integer :: i, j, k
10 integer :: N = 256
11 real(8) :: a(256)
13 !$acc parallel
14 !$acc loop
15 do i = 1, N
16 a(i) = 3.14
17 !ERROR: RETURN statement is not allowed in a PARALLEL construct
18 return
19 end do
20 !$acc end parallel
22 !$acc parallel
23 !$acc loop
24 do i = 1, N
25 a(i) = 3.14
26 if(i == N-1) THEN
27 exit
28 end if
29 end do
30 !$acc end parallel
32 ! Exit branches out of parallel construct, not attached to an OpenACC parallel construct.
33 name1: do k=1, N
34 !$acc parallel
35 !$acc loop
36 outer: do i=1, N
37 inner: do j=1, N
38 ifname: if (j == 2) then
39 ! These are allowed.
40 exit
41 exit inner
42 exit outer
43 !ERROR: EXIT to construct 'name1' outside of PARALLEL construct is not allowed
44 exit name1
45 ! Exit to construct other than loops.
46 exit ifname
47 end if ifname
48 end do inner
49 end do outer
50 !$acc end parallel
51 end do name1
53 ! Exit branches out of parallel construct, attached to an OpenACC parallel construct.
54 thisblk: BLOCK
55 fortname: if (.true.) then
56 name1: do k = 1, N
57 !$acc parallel
58 !ERROR: EXIT to construct 'fortname' outside of PARALLEL construct is not allowed
59 exit fortname
60 !$acc loop
61 do i = 1, N
62 a(i) = 3.14
63 if(i == N-1) THEN
64 !ERROR: EXIT to construct 'name1' outside of PARALLEL construct is not allowed
65 exit name1
66 end if
67 end do
69 loop2: do i = 1, N
70 a(i) = 3.33
71 !ERROR: EXIT to construct 'thisblk' outside of PARALLEL construct is not allowed
72 exit thisblk
73 end do loop2
74 !$acc end parallel
75 end do name1
76 end if fortname
77 end BLOCK thisblk
79 !Exit branches inside OpenACC construct.
80 !$acc parallel
81 !$acc loop
82 do i = 1, N
83 a(i) = 3.14
84 ifname: if (i == 2) then
85 ! This is allowed.
86 exit ifname
87 end if ifname
88 end do
89 !$acc end parallel
91 !$acc parallel
92 !$acc loop
93 do i = 1, N
94 a(i) = 3.14
95 if(i == N-1) THEN
96 !ERROR: STOP statement is not allowed in a PARALLEL construct
97 stop 999
98 end if
99 end do
100 !$acc end parallel
102 !$acc kernels
103 do i = 1, N
104 a(i) = 3.14
105 !ERROR: RETURN statement is not allowed in a KERNELS construct
106 return
107 end do
108 !$acc end kernels
110 !$acc kernels
111 do i = 1, N
112 a(i) = 3.14
113 if(i == N-1) THEN
114 exit
115 end if
116 end do
117 !$acc end kernels
119 !$acc kernels
120 do i = 1, N
121 a(i) = 3.14
122 if(i == N-1) THEN
123 !ERROR: STOP statement is not allowed in a KERNELS construct
124 stop 999
125 end if
126 end do
127 !$acc end kernels
129 !$acc serial
130 do i = 1, N
131 a(i) = 3.14
132 !ERROR: RETURN statement is not allowed in a SERIAL construct
133 return
134 end do
135 !$acc end serial
137 !$acc serial
138 do i = 1, N
139 a(i) = 3.14
140 if(i == N-1) THEN
141 exit
142 end if
143 end do
144 !$acc end serial
146 name2: do k=1, N
147 !$acc serial
148 do i = 1, N
149 ifname: if (.true.) then
150 print *, "LGTM"
151 a(i) = 3.14
152 if(i == N-1) THEN
153 !ERROR: EXIT to construct 'name2' outside of SERIAL construct is not allowed
154 exit name2
155 exit ifname
156 end if
157 end if ifname
158 end do
159 !$acc end serial
160 end do name2
162 !$acc serial
163 do i = 1, N
164 a(i) = 3.14
165 if(i == N-1) THEN
166 !ERROR: STOP statement is not allowed in a SERIAL construct
167 stop 999
168 end if
169 end do
170 !$acc end serial
172 end program openacc_clause_validity