Skip to content

Commit

Permalink
[flang] Fix crash on erroneous program (#88192)
Browse files Browse the repository at this point in the history
Constant folding had a CHECK on array subscript rank that should more
gracefully handle a bad program with a subscript that is a matrix or
higher rank.

Fixes #88112.
  • Loading branch information
klausler authored Apr 22, 2024
1 parent 6884c1f commit 138524e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flang/lib/Evaluate/fold-implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,12 @@ std::optional<Constant<T>> Folder<T>::ApplySubscripts(const Constant<T> &array,
ConstantSubscripts resultShape;
ConstantSubscripts ssLB;
for (const auto &ss : subscripts) {
CHECK(ss.Rank() <= 1);
if (ss.Rank() == 1) {
resultShape.push_back(static_cast<ConstantSubscript>(ss.size()));
elements *= ss.size();
ssLB.push_back(ss.lbounds().front());
} else if (ss.Rank() > 1) {
return std::nullopt; // error recovery
}
}
ConstantSubscripts ssAt(rank, 0), at(rank, 0), tmp(1, 0);
Expand Down

0 comments on commit 138524e

Please sign in to comment.