Skip to content

Commit

Permalink
[flang] Fix crash in fuzzed input program (llvm#122193)
Browse files Browse the repository at this point in the history
  • Loading branch information
klausler authored and DKLoehr committed Jan 17, 2025
1 parent 2bd5f65 commit 8e68a9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions flang/lib/Evaluate/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions flang/test/Semantics/bug121971.f90
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8e68a9e

Please sign in to comment.