@@ -1183,13 +1183,23 @@ void AccAttributeVisitor::CheckAssociatedLoopIndex(
1183
1183
}
1184
1184
1185
1185
const auto getNextDoConstruct =
1186
- [this ](const parser::Block &block) -> const parser::DoConstruct * {
1186
+ [this ](const parser::Block &block,
1187
+ std::int64_t &level) -> const parser::DoConstruct * {
1187
1188
for (const auto &entry : block) {
1188
1189
if (const auto *doConstruct = GetDoConstructIf (entry)) {
1189
1190
return doConstruct;
1190
1191
} else if (parser::Unwrap<parser::CompilerDirective>(entry)) {
1191
1192
// It is allowed to have a compiler directive associated with the loop.
1192
1193
continue ;
1194
+ } else if (const auto &accLoop{
1195
+ parser::Unwrap<parser::OpenACCLoopConstruct>(entry)}) {
1196
+ if (level == 0 )
1197
+ break ;
1198
+ const auto &beginDir{
1199
+ std::get<parser::AccBeginLoopDirective>(accLoop->t )};
1200
+ context_.Say (beginDir.source ,
1201
+ " LOOP directive not expected in COLLAPSE loop nest" _err_en_US);
1202
+ level = 0 ;
1193
1203
} else {
1194
1204
break ;
1195
1205
}
@@ -1198,11 +1208,12 @@ void AccAttributeVisitor::CheckAssociatedLoopIndex(
1198
1208
};
1199
1209
1200
1210
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t )};
1201
- for (const parser::DoConstruct *loop{&*outer}; loop && level > 0 ; --level ) {
1211
+ for (const parser::DoConstruct *loop{&*outer}; loop && level > 0 ;) {
1202
1212
// Go through all nested loops to ensure index variable exists.
1203
1213
GetLoopIndex (*loop);
1204
1214
const auto &block{std::get<parser::Block>(loop->t )};
1205
- loop = getNextDoConstruct (block);
1215
+ --level;
1216
+ loop = getNextDoConstruct (block, level);
1206
1217
}
1207
1218
CHECK (level == 0 );
1208
1219
}
0 commit comments