Skip to content

Commit fbf716f

Browse files
vzakharitru
authored andcommitted
[flang] Fixed restrictions checking for OpenACC loop-associated constructs.
CheckDoConcurrentClauseRestriction and CheckTileClauseRestriction expect that the construct has associated DoConstruct, while it is not set when the do-loop has no loop control. The change is to skip the clauses checks, when the do-loop does not have the loop control. An alternative fix would be to associate the DoConstruct even when the do-loop has no loop control and let Check*ClauseRestriction run their checks, but I am not sure if associating invalid DoConstruct is a good idea. This fixes failure in Semantics/OpenACC/acc-canonicalization-validity.f90 reported in D142279. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D142652 (cherry picked from commit 0244526)
1 parent 2ecbe73 commit fbf716f

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

flang/lib/Semantics/canonicalize-acc.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ class CanonicalizationOfAcc {
127127
nextIt = it;
128128
if (++nextIt != block.end()) {
129129
if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
130-
if (doCons->GetLoopControl()) {
131-
// move DoConstruct
132-
std::get<std::optional<parser::DoConstruct>>(x.t) =
133-
std::move(*doCons);
134-
nextIt = block.erase(nextIt);
135-
} else {
130+
if (!doCons->GetLoopControl()) {
136131
messages_.Say(dir.source,
137132
"DO loop after the %s directive must have loop control"_err_en_US,
138133
parser::ToUpperCaseLetters(dir.source.ToString()));
134+
return;
139135
}
140136

137+
// move DoConstruct
138+
std::get<std::optional<parser::DoConstruct>>(x.t) = std::move(*doCons);
139+
nextIt = block.erase(nextIt);
140+
141141
CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
142142
parser::AccBeginLoopDirective>(x);
143143
CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
@@ -173,24 +173,23 @@ class CanonicalizationOfAcc {
173173
nextIt = it;
174174
if (++nextIt != block.end()) {
175175
if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
176-
if (doCons->GetLoopControl()) {
177-
// move DoConstruct
178-
std::get<std::optional<parser::DoConstruct>>(x.t) =
179-
std::move(*doCons);
180-
nextIt = block.erase(nextIt);
181-
// try to match AccEndCombinedDirective
182-
if (nextIt != block.end()) {
183-
if (auto *endDir{
184-
parser::Unwrap<parser::AccEndCombinedDirective>(*nextIt)}) {
185-
std::get<std::optional<parser::AccEndCombinedDirective>>(x.t) =
186-
std::move(*endDir);
187-
block.erase(nextIt);
188-
}
189-
}
190-
} else {
176+
if (!doCons->GetLoopControl()) {
191177
messages_.Say(dir.source,
192178
"DO loop after the %s directive must have loop control"_err_en_US,
193179
parser::ToUpperCaseLetters(dir.source.ToString()));
180+
return;
181+
}
182+
// move DoConstruct
183+
std::get<std::optional<parser::DoConstruct>>(x.t) = std::move(*doCons);
184+
nextIt = block.erase(nextIt);
185+
// try to match AccEndCombinedDirective
186+
if (nextIt != block.end()) {
187+
if (auto *endDir{
188+
parser::Unwrap<parser::AccEndCombinedDirective>(*nextIt)}) {
189+
std::get<std::optional<parser::AccEndCombinedDirective>>(x.t) =
190+
std::move(*endDir);
191+
block.erase(nextIt);
192+
}
194193
}
195194

196195
CheckDoConcurrentClauseRestriction<parser::OpenACCCombinedConstruct,

0 commit comments

Comments
 (0)