Skip to content

Commit bf23ae6

Browse files
authored
[flang] Fix crash in fuzzed input program (#122193)
Fixes #121971.
1 parent dcc141b commit bf23ae6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

flang/lib/Evaluate/shape.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,13 @@ MaybeExtentExpr GetExtent(const Subscript &subscript, const NamedEntity &base,
566566
MaybeExtentExpr{triplet.stride()});
567567
},
568568
[&](const IndirectSubscriptIntegerExpr &subs) -> MaybeExtentExpr {
569-
if (auto shape{GetShape(subs.value())}) {
570-
if (GetRank(*shape) > 0) {
571-
CHECK(GetRank(*shape) == 1); // vector-valued subscript
572-
return std::move(shape->at(0));
573-
}
569+
if (auto shape{GetShape(subs.value())};
570+
shape && GetRank(*shape) == 1) {
571+
// vector-valued subscript
572+
return std::move(shape->at(0));
573+
} else {
574+
return std::nullopt;
574575
}
575-
return std::nullopt;
576576
},
577577
},
578578
subscript.u);

flang/test/Semantics/bug121971.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
subroutine subr(a,b,n,m)
3+
real n,m
4+
!ERROR: Must have INTEGER type, but is REAL(4)
5+
!ERROR: Must have INTEGER type, but is REAL(4)
6+
integer a(n,m)
7+
!ERROR: Rank of left-hand side is 2, but right-hand side has rank 1
8+
!ERROR: Subscript expression has rank 2 greater than 1
9+
a = a(a,j)
10+
end

0 commit comments

Comments
 (0)