[flang] Runtime validation of SPREAD(DIM=dim) argument

Crash when DIM= is not a valid dimension in the result.

Differential Revision: https://reviews.llvm.org/D121145
This commit is contained in:
Peter Klausler 2022-02-23 14:16:10 -08:00
parent abc2c2309a
commit 764363368c

View file

@ -456,6 +456,11 @@ void RTNAME(Spread)(Descriptor &result, const Descriptor &source, int dim,
Terminator terminator{sourceFile, line}; Terminator terminator{sourceFile, line};
int rank{source.rank() + 1}; int rank{source.rank() + 1};
RUNTIME_CHECK(terminator, rank <= maxRank); RUNTIME_CHECK(terminator, rank <= maxRank);
if (dim < 1 || dim > rank) {
terminator.Crash("SPREAD: DIM=%d argument for rank-%d source array "
"must be greater than 1 and less than or equal to %d",
dim, rank - 1, rank);
}
ncopies = std::max<std::int64_t>(ncopies, 0); ncopies = std::max<std::int64_t>(ncopies, 0);
SubscriptValue extent[maxRank]; SubscriptValue extent[maxRank];
int k{0}; int k{0};