mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-10-07 19:03:57 +00:00
[flang][openacc] Avoid crash when collapse loop nest has extra directive (#73166)
The compiler was crashing when the collapse loop nest could not be retrieved because of extra acc loop directive inside it.
This commit is contained in:
parent
53f912480f
commit
575c9bf940
@ -1183,13 +1183,23 @@ void AccAttributeVisitor::CheckAssociatedLoopIndex(
|
||||
}
|
||||
|
||||
const auto getNextDoConstruct =
|
||||
[this](const parser::Block &block) -> const parser::DoConstruct * {
|
||||
[this](const parser::Block &block,
|
||||
std::int64_t &level) -> const parser::DoConstruct * {
|
||||
for (const auto &entry : block) {
|
||||
if (const auto *doConstruct = GetDoConstructIf(entry)) {
|
||||
return doConstruct;
|
||||
} else if (parser::Unwrap<parser::CompilerDirective>(entry)) {
|
||||
// It is allowed to have a compiler directive associated with the loop.
|
||||
continue;
|
||||
} else if (const auto &accLoop{
|
||||
parser::Unwrap<parser::OpenACCLoopConstruct>(entry)}) {
|
||||
if (level == 0)
|
||||
break;
|
||||
const auto &beginDir{
|
||||
std::get<parser::AccBeginLoopDirective>(accLoop->t)};
|
||||
context_.Say(beginDir.source,
|
||||
"LOOP directive not expected in COLLAPSE loop nest"_err_en_US);
|
||||
level = 0;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -1198,11 +1208,12 @@ void AccAttributeVisitor::CheckAssociatedLoopIndex(
|
||||
};
|
||||
|
||||
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
|
||||
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
|
||||
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0;) {
|
||||
// Go through all nested loops to ensure index variable exists.
|
||||
GetLoopIndex(*loop);
|
||||
const auto &block{std::get<parser::Block>(loop->t)};
|
||||
loop = getNextDoConstruct(block);
|
||||
--level;
|
||||
loop = getNextDoConstruct(block, level);
|
||||
}
|
||||
CHECK(level == 0);
|
||||
}
|
||||
|
@ -268,4 +268,12 @@ program openacc_loop_validity
|
||||
end do
|
||||
!$acc end loop
|
||||
|
||||
!$acc loop collapse(2)
|
||||
do i = 1, 10
|
||||
!ERROR: LOOP directive not expected in COLLAPSE loop nest
|
||||
!$acc loop
|
||||
do j = 1, 10
|
||||
end do
|
||||
end do
|
||||
|
||||
end program openacc_loop_validity
|
||||
|
Loading…
Reference in New Issue
Block a user