[flang-commits] [flang] 138524e - [flang] Fix crash on erroneous program (#88192)
via flang-commits
flang-commits at lists.llvm.org
Mon Apr 22 15:01:04 PDT 2024
Author: Peter Klausler
Date: 2024-04-22T15:01:01-07:00
New Revision: 138524ef8ea9d63e47d78f5e344c263e769a293e
URL: https://github.com/llvm/llvm-project/commit/138524ef8ea9d63e47d78f5e344c263e769a293e
DIFF: https://github.com/llvm/llvm-project/commit/138524ef8ea9d63e47d78f5e344c263e769a293e.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/88112.
Added:
Modified:
flang/lib/Evaluate/fold-implementation.h
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 34f79f9e6f25b4..093f26bea1a44f 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -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);
More information about the flang-commits
mailing list