@@ -109,21 +109,37 @@ class CanonicalizationOfAcc {
109109
110110 void RewriteOpenACCLoopConstruct (parser::OpenACCLoopConstruct &x,
111111 parser::Block &block, parser::Block::iterator it) {
112+ parser::Block::iterator nextIt;
112113 auto &beginDir{std::get<parser::AccBeginLoopDirective>(x.t )};
113114 auto &dir{std::get<parser::AccLoopDirective>(beginDir.t )};
114- const auto &doCons{std::get<parser::DoConstruct>(x.t )};
115+ auto &nestedDo{std::get<std::optional<parser::DoConstruct>>(x.t )};
116+
117+ if (!nestedDo) {
118+ nextIt = it;
119+ if (++nextIt != block.end ()) {
120+ if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
121+ nestedDo = std::move (*doCons);
122+ nextIt = block.erase (nextIt);
123+ }
124+ }
125+ }
115126
116- if (!doCons.GetLoopControl ()) {
117- messages_.Say (dir.source ,
118- " DO loop after the %s directive must have loop control" _err_en_US,
119- parser::ToUpperCaseLetters (dir.source .ToString ()));
127+ if (nestedDo) {
128+ if (!nestedDo->GetLoopControl ()) {
129+ messages_.Say (dir.source ,
130+ " DO loop after the %s directive must have loop control" _err_en_US,
131+ parser::ToUpperCaseLetters (dir.source .ToString ()));
132+ return ;
133+ }
134+ CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
135+ parser::AccBeginLoopDirective>(x, *nestedDo);
136+ CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
137+ parser::AccBeginLoopDirective>(x, *nestedDo);
120138 return ;
121139 }
122-
123- CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
124- parser::AccBeginLoopDirective>(x, doCons);
125- CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
126- parser::AccBeginLoopDirective>(x, doCons);
140+ messages_.Say (dir.source ,
141+ " A DO loop must follow the %s directive" _err_en_US,
142+ parser::ToUpperCaseLetters (dir.source .ToString ()));
127143 }
128144
129145 void RewriteOpenACCCombinedConstruct (parser::OpenACCCombinedConstruct &x,
0 commit comments