Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,14 +2303,17 @@ void OmpAttributeVisitor::CheckPerfectNestAndRectangularLoop(
}

auto checkPerfectNest = [&, this]() {
auto blockSize = block.size();
if (blockSize <= 1)
if (block.empty())
return;
auto last = block.end();
--last;

if (parser::Unwrap<parser::ContinueStmt>(x))
blockSize -= 1;
// A trailing CONTINUE is not considered part of the loop body
if (parser::Unwrap<parser::ContinueStmt>(*last))
--last;

if (blockSize <= 1)
// In a perfectly nested loop, the nested loop must be the only statement
if (last == block.begin())
return;

// Non-perfectly nested loop
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Lower/OpenMP/wsloop-collapse-continue.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s

program wsloop_collapse_continue
integer i, j

! CHECK: omp.wsloop {{.*}} {
! CHECK: omp.loop_nest ({{.*}}) : i32 = ({{.*}}) to ({{.*}}) inclusive step ({{.*}}) collapse(2) {
!$omp do collapse(2)
do 50 i = 1, 42
do 51 j = 1, 84
! CHECK: fir.call @_FortranAioOutputInteger32(
print *, i
! CHECK: fir.call @_FortranAioOutputInteger32(
print *, j
51 continue
50 continue
!$omp end do

end program wsloop_collapse_continue
1 change: 0 additions & 1 deletion flang/test/Semantics/OpenMP/do08.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ program omp
!$omp end do


!ERROR: Canonical loop nest must be perfectly nested.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ERRORs were added in #60283. Those are still non-perfectly nested loops, but the other errors get precedence.

!ERROR: The value of the parameter in the COLLAPSE or ORDERED clause must not be larger than the number of nested loops following the construct.
!$omp do collapse(3)
do 60 i=2,200,2
Expand Down
1 change: 0 additions & 1 deletion flang/test/Semantics/OpenMP/do13.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ program omp
!$omp end do


!ERROR: Canonical loop nest must be perfectly nested.
!ERROR: The value of the parameter in the COLLAPSE or ORDERED clause must not be larger than the number of nested loops following the construct.
!$omp do collapse(3)
do 60 i=1,10
Expand Down