[flang] Fix crash in fuzzed input program (#122193)

Fixes https://github.com/llvm/llvm-project/issues/121971.
This commit is contained in:
Peter Klausler 2025-01-14 10:39:51 -08:00 committed by GitHub
parent dcc141bc0b
commit bf23ae6d38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View File

@ -566,13 +566,13 @@ MaybeExtentExpr GetExtent(const Subscript &subscript, const NamedEntity &base,
MaybeExtentExpr{triplet.stride()});
},
[&](const IndirectSubscriptIntegerExpr &subs) -> MaybeExtentExpr {
if (auto shape{GetShape(subs.value())}) {
if (GetRank(*shape) > 0) {
CHECK(GetRank(*shape) == 1); // vector-valued subscript
return std::move(shape->at(0));
}
if (auto shape{GetShape(subs.value())};
shape && GetRank(*shape) == 1) {
// vector-valued subscript
return std::move(shape->at(0));
} else {
return std::nullopt;
}
return std::nullopt;
},
},
subscript.u);

View File

@ -0,0 +1,10 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
subroutine subr(a,b,n,m)
real n,m
!ERROR: Must have INTEGER type, but is REAL(4)
!ERROR: Must have INTEGER type, but is REAL(4)
integer a(n,m)
!ERROR: Rank of left-hand side is 2, but right-hand side has rank 1
!ERROR: Subscript expression has rank 2 greater than 1
a = a(a,j)
end