Skip to content

Commit a87ca1b

Browse files
authored
[flang][openacc] Do not check for unlabelled CYCLE branching (#73839)
There is no such restriction for any OpenACC construct. This patch adds a constexpr condition on the type of Directive.
1 parent bf2e05c commit a87ca1b

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

flang/lib/Semantics/check-directive-structure.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@ template <typename D> class NoBranchingEnforce {
6262
if (const auto &cycleName{cycleStmt.v}) {
6363
CheckConstructNameBranching("CYCLE", cycleName.value());
6464
} else {
65-
switch ((llvm::omp::Directive)currentDirective_) {
66-
// exclude directives which do not need a check for unlabelled CYCLES
67-
case llvm::omp::Directive::OMPD_do:
68-
case llvm::omp::Directive::OMPD_simd:
69-
case llvm::omp::Directive::OMPD_parallel_do:
70-
case llvm::omp::Directive::OMPD_parallel_do_simd:
71-
case llvm::omp::Directive::OMPD_distribute_parallel_do:
72-
case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
73-
case llvm::omp::Directive::OMPD_distribute_parallel_for:
74-
case llvm::omp::Directive::OMPD_distribute_simd:
75-
case llvm::omp::Directive::OMPD_distribute_parallel_for_simd:
76-
return;
77-
default:
78-
break;
65+
if constexpr (std::is_same_v<D, llvm::omp::Directive>) {
66+
switch ((llvm::omp::Directive)currentDirective_) {
67+
// exclude directives which do not need a check for unlabelled CYCLES
68+
case llvm::omp::Directive::OMPD_do:
69+
case llvm::omp::Directive::OMPD_simd:
70+
case llvm::omp::Directive::OMPD_parallel_do:
71+
case llvm::omp::Directive::OMPD_parallel_do_simd:
72+
case llvm::omp::Directive::OMPD_distribute_parallel_do:
73+
case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
74+
case llvm::omp::Directive::OMPD_distribute_parallel_for:
75+
case llvm::omp::Directive::OMPD_distribute_simd:
76+
case llvm::omp::Directive::OMPD_distribute_parallel_for_simd:
77+
return;
78+
default:
79+
break;
80+
}
81+
} else if constexpr (std::is_same_v<D, llvm::acc::Directive>) {
82+
return; // OpenACC construct do not need check for unlabelled CYCLES
7983
}
8084
CheckConstructNameBranching("CYCLE");
8185
}

flang/test/Semantics/OpenACC/acc-kernels-loop.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,9 @@ program openacc_kernels_loop_validity
290290
a(i) = 3.14
291291
end do
292292

293+
!$acc parallel loop
294+
do i = 1, N
295+
if(i == 10) cycle
296+
end do
297+
293298
end program openacc_kernels_loop_validity

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,11 @@ program openacc_loop_validity
276276
end do
277277
end do
278278

279+
!$acc parallel
280+
!$acc loop
281+
do i = 1, n
282+
if(i == 10) cycle
283+
end do
284+
!$acc end parallel
285+
279286
end program openacc_loop_validity

flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,9 @@ program openacc_parallel_loop_validity
136136
reduction_l = d(i) .neqv. e(i)
137137
end do
138138

139+
!$acc parallel loop
140+
do i = 1, N
141+
if(i == 10) cycle
142+
end do
143+
139144
end program openacc_parallel_loop_validity

flang/test/Semantics/OpenACC/acc-serial-loop.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,9 @@ program openacc_serial_loop_validity
106106
end do
107107
!$acc end serial
108108

109+
!$acc serial loop
110+
do i = 1, n
111+
if(i == 10) cycle
112+
end do
113+
109114
end program openacc_serial_loop_validity

0 commit comments

Comments
 (0)