@@ -1895,22 +1895,29 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
18951895 }
18961896
18971897 const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t )};
1898- for (const parser::DoConstruct *loop{&*outer}; loop && level > 0 ; --level) {
1899- // go through all the nested do-loops and resolve index variables
1900- const parser::Name *iv{GetLoopIndex (*loop)};
1901- if (iv) {
1902- if (auto *symbol{ResolveOmp (*iv, ivDSA, currScope ())}) {
1903- symbol->set (Symbol::Flag::OmpPreDetermined);
1904- iv->symbol = symbol; // adjust the symbol within region
1905- AddToContextObjectWithDSA (*symbol, ivDSA);
1906- }
1898+ if (outer.has_value ()) {
1899+ for (const parser::DoConstruct *loop{&*outer}; loop && level > 0 ; --level) {
1900+ // go through all the nested do-loops and resolve index variables
1901+ const parser::Name *iv{GetLoopIndex (*loop)};
1902+ if (iv) {
1903+ if (auto *symbol{ResolveOmp (*iv, ivDSA, currScope ())}) {
1904+ symbol->set (Symbol::Flag::OmpPreDetermined);
1905+ iv->symbol = symbol; // adjust the symbol within region
1906+ AddToContextObjectWithDSA (*symbol, ivDSA);
1907+ }
19071908
1908- const auto &block{std::get<parser::Block>(loop->t )};
1909- const auto it{block.begin ()};
1910- loop = it != block.end () ? GetDoConstructIf (*it) : nullptr ;
1909+ const auto &block{std::get<parser::Block>(loop->t )};
1910+ const auto it{block.begin ()};
1911+ loop = it != block.end () ? GetDoConstructIf (*it) : nullptr ;
1912+ }
19111913 }
1914+ CheckAssocLoopLevel (level, GetAssociatedClause ());
1915+ } else {
1916+ context_.Say (GetContext ().directiveSource ,
1917+ " A DO loop must follow the %s directive" _err_en_US,
1918+ parser::ToUpperCaseLetters (
1919+ llvm::omp::getOpenMPDirectiveName (GetContext ().directive ).str ()));
19121920 }
1913- CheckAssocLoopLevel (level, GetAssociatedClause ());
19141921}
19151922void OmpAttributeVisitor::CheckAssocLoopLevel (
19161923 std::int64_t level, const parser::OmpClause *clause) {
0 commit comments