Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions flang/lib/Semantics/canonicalize-omp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ class CanonicalizationOfOmp {
auto &dir{std::get<parser::OmpLoopDirective>(beginDir.t)};

nextIt = it;
if (++nextIt != block.end()) {
while (++nextIt != block.end()) {
// Ignore compiler directives.
if (auto *directive{GetConstructIf<parser::CompilerDirective>(*nextIt)})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting a warning on this line because the variable directive isn't used. And since I have -Werror set, my build fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies for that. Neither my GCC nor my Clang builds that I run warned for this - Trivial fix here:

#81604

continue;

if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
if (doCons->GetLoopControl()) {
// move DoConstruct
Expand All @@ -111,12 +115,14 @@ class CanonicalizationOfOmp {
"DO loop after the %s directive must have loop control"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
}
return; // found do-loop
} else {
messages_.Say(dir.source,
"A DO loop must follow the %s directive"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
}
// If we get here, we either found a loop, or issued an error message.
return;
}
messages_.Say(dir.source,
"A DO loop must follow the %s directive"_err_en_US,
parser::ToUpperCaseLetters(dir.source.ToString()));
}

void RewriteOmpAllocations(parser::ExecutionPart &body) {
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/OpenMP/loop-association.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
c = c - 1
END DO outer

! Accept directives between parallel do and actual loop.
!$OMP PARALLEL DO
!DIR$ VECTOR ALIGNED
DO 20 i=1,N
a = a + 0.5
20 CONTINUE

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this needs an !$OMP END PARALLEL DO to be valid openmp

Copy link
Contributor

Choose a reason for hiding this comment

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

For the worksharing loop directives, the closing END directive is optional. However, I agree with the nit and we should have as a matter of style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add it, because it wasn't in the other tests that do similar loops. But I agree, it's nicer to have, so I have added it now.

c = 16
!ERROR: DO loop after the PARALLEL DO directive must have loop control
!$omp parallel do
Expand Down