Skip to content

Commit f4c5c47

Browse files
authored
[flang][openacc] Enforce no branching out of compute region for combined construct (#73581)
`A program may not branch into or out of a compute construct.` This restriction is also true for combined constructs. This patch enforce this rule.
1 parent 3e5acc7 commit f4c5c47

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

flang/lib/Semantics/check-acc-structure.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,18 @@ void AccStructureChecker::Leave(const parser::OpenACCCombinedConstruct &x) {
218218
const auto &beginBlockDir{std::get<parser::AccBeginCombinedDirective>(x.t)};
219219
const auto &combinedDir{
220220
std::get<parser::AccCombinedDirective>(beginBlockDir.t)};
221+
auto &doCons{std::get<std::optional<parser::DoConstruct>>(x.t)};
221222
switch (combinedDir.v) {
222223
case llvm::acc::Directive::ACCD_kernels_loop:
223224
case llvm::acc::Directive::ACCD_parallel_loop:
224225
case llvm::acc::Directive::ACCD_serial_loop:
225226
// Restriction - line 1004-1005
226227
CheckOnlyAllowedAfter(llvm::acc::Clause::ACCC_device_type,
227228
computeConstructOnlyAllowedAfterDeviceTypeClauses);
229+
if (doCons) {
230+
const parser::Block &block{std::get<parser::Block>(doCons->t)};
231+
CheckNoBranching(block, GetContext().directive, beginBlockDir.source);
232+
}
228233
break;
229234
default:
230235
break;

flang/test/Parser/acc-unparse.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ program bug47659
99
!$acc parallel loop
1010
do j = 1, 10
1111
if (j == 2) then
12-
exit label1
12+
stop 1
1313
end if
1414
end do
1515
end do label1

flang/test/Semantics/OpenACC/acc-branch.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ subroutine openacc_clause_validity
1919
end do
2020
!$acc end parallel
2121

22+
!$acc parallel loop
23+
do i = 1, N
24+
a(i) = 3.14
25+
!ERROR: RETURN statement is not allowed in a PARALLEL LOOP construct
26+
return
27+
end do
28+
29+
!$acc serial loop
30+
do i = 1, N
31+
a(i) = 3.14
32+
!ERROR: RETURN statement is not allowed in a SERIAL LOOP construct
33+
return
34+
end do
35+
36+
!$acc kernels loop
37+
do i = 1, N
38+
a(i) = 3.14
39+
!ERROR: RETURN statement is not allowed in a KERNELS LOOP construct
40+
return
41+
end do
42+
2243
!$acc parallel
2344
!$acc loop
2445
do i = 1, N

0 commit comments

Comments
 (0)