Skip to content

Commit 138524e

Browse files
authored
[flang] Fix crash on erroneous program (#88192)
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.
1 parent 6884c1f commit 138524e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

flang/lib/Evaluate/fold-implementation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ std::optional<Constant<T>> Folder<T>::ApplySubscripts(const Constant<T> &array,
201201
ConstantSubscripts resultShape;
202202
ConstantSubscripts ssLB;
203203
for (const auto &ss : subscripts) {
204-
CHECK(ss.Rank() <= 1);
205204
if (ss.Rank() == 1) {
206205
resultShape.push_back(static_cast<ConstantSubscript>(ss.size()));
207206
elements *= ss.size();
208207
ssLB.push_back(ss.lbounds().front());
208+
} else if (ss.Rank() > 1) {
209+
return std::nullopt; // error recovery
209210
}
210211
}
211212
ConstantSubscripts ssAt(rank, 0), at(rank, 0), tmp(1, 0);

0 commit comments

Comments
 (0)