diff --git a/flang/lib/Semantics/canonicalize-acc.cpp b/flang/lib/Semantics/canonicalize-acc.cpp index 855f62f53ff8d..5afae172cfaa2 100644 --- a/flang/lib/Semantics/canonicalize-acc.cpp +++ b/flang/lib/Semantics/canonicalize-acc.cpp @@ -127,17 +127,17 @@ class CanonicalizationOfAcc { nextIt = it; if (++nextIt != block.end()) { if (auto *doCons{parser::Unwrap(*nextIt)}) { - if (doCons->GetLoopControl()) { - // move DoConstruct - std::get>(x.t) = - std::move(*doCons); - nextIt = block.erase(nextIt); - } else { + if (!doCons->GetLoopControl()) { messages_.Say(dir.source, "DO loop after the %s directive must have loop control"_err_en_US, parser::ToUpperCaseLetters(dir.source.ToString())); + return; } + // move DoConstruct + std::get>(x.t) = std::move(*doCons); + nextIt = block.erase(nextIt); + CheckDoConcurrentClauseRestriction(x); CheckTileClauseRestriction(*nextIt)}) { - if (doCons->GetLoopControl()) { - // move DoConstruct - std::get>(x.t) = - std::move(*doCons); - nextIt = block.erase(nextIt); - // try to match AccEndCombinedDirective - if (nextIt != block.end()) { - if (auto *endDir{ - parser::Unwrap(*nextIt)}) { - std::get>(x.t) = - std::move(*endDir); - block.erase(nextIt); - } - } - } else { + if (!doCons->GetLoopControl()) { messages_.Say(dir.source, "DO loop after the %s directive must have loop control"_err_en_US, parser::ToUpperCaseLetters(dir.source.ToString())); + return; + } + // move DoConstruct + std::get>(x.t) = std::move(*doCons); + nextIt = block.erase(nextIt); + // try to match AccEndCombinedDirective + if (nextIt != block.end()) { + if (auto *endDir{ + parser::Unwrap(*nextIt)}) { + std::get>(x.t) = + std::move(*endDir); + block.erase(nextIt); + } } CheckDoConcurrentClauseRestriction