Skip to content

Commit b2b3a52

Browse files
Skip compiler directives between OMP PARALLEL DO and the loop (#81021)
This fixes a compilation error when code like this is presented to the compiler: !$OMP PARALLEL DO !DIR$ VECTOR ALIGNED DO 20 i=1,N a = a + 0.5 20 CONTINUE The directive itself is later ignored (with a warning that this is happening), but because the compiler already errored out before that point, it completely fails to compile this code. Other compilers accept the code without complaints.
1 parent 301f684 commit b2b3a52

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ class CanonicalizationOfOmp {
9090
auto &dir{std::get<parser::OmpLoopDirective>(beginDir.t)};
9191

9292
nextIt = it;
93-
if (++nextIt != block.end()) {
93+
while (++nextIt != block.end()) {
94+
// Ignore compiler directives.
95+
if (auto *directive{GetConstructIf<parser::CompilerDirective>(*nextIt)})
96+
continue;
97+
9498
if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
9599
if (doCons->GetLoopControl()) {
96100
// move DoConstruct
@@ -111,12 +115,14 @@ class CanonicalizationOfOmp {
111115
"DO loop after the %s directive must have loop control"_err_en_US,
112116
parser::ToUpperCaseLetters(dir.source.ToString()));
113117
}
114-
return; // found do-loop
118+
} else {
119+
messages_.Say(dir.source,
120+
"A DO loop must follow the %s directive"_err_en_US,
121+
parser::ToUpperCaseLetters(dir.source.ToString()));
115122
}
123+
// If we get here, we either found a loop, or issued an error message.
124+
return;
116125
}
117-
messages_.Say(dir.source,
118-
"A DO loop must follow the %s directive"_err_en_US,
119-
parser::ToUpperCaseLetters(dir.source.ToString()));
120126
}
121127

122128
void RewriteOmpAllocations(parser::ExecutionPart &body) {

flang/test/Semantics/OpenMP/loop-association.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
c = c - 1
3131
END DO outer
3232

33+
! Accept directives between parallel do and actual loop.
34+
!$OMP PARALLEL DO
35+
!DIR$ VECTOR ALIGNED
36+
DO 20 i=1,N
37+
a = a + 0.5
38+
20 CONTINUE
39+
!$OMP END PARALLEL DO
40+
3341
c = 16
3442
!ERROR: DO loop after the PARALLEL DO directive must have loop control
3543
!$omp parallel do

0 commit comments

Comments
 (0)