[flang] Fix a crash when cosubscript list is empty

Summary:
When there are errors in the evaluation of every cosubscript expression in a
coindexed object, the compiler would crash.  I fixed this by just checking to
see if there were errors in the evaluation of the cosubscripts before
constructing the `DataRef` for the coindexed object.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83410
This commit is contained in:
Pete Steinfeld 2020-07-08 10:05:04 -07:00
parent 1eaad01046
commit 9520b6c8ab
2 changed files with 9 additions and 4 deletions

View File

@ -1089,15 +1089,17 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::CoindexedNamedObject &x) {
std::get<std::list<parser::ImageSelectorSpec>>(x.imageSelector.t)) {
std::visit(
common::visitors{
[&](const auto &x) {Analyze(x.v); },
[&](const auto &x) { Analyze(x.v); },
},
imageSelSpec.u);
}
// Reverse the chain of symbols so that the base is first and coarray
// ultimate component is last.
return Designate(
DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()},
std::move(subscripts), std::move(cosubscripts)}});
if (cosubsOk) {
return Designate(
DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()},
std::move(subscripts), std::move(cosubscripts)}});
}
}
return std::nullopt;
}

View File

@ -13,6 +13,7 @@ subroutine s1()
integer, dimension(4) :: intArray
integer :: intScalarCoarray[*]
integer :: intCoarray[3, 4, *]
integer :: smallIntCoarray[4, *]
intCoVar = 343
! OK
rVar1 = rCoarray[1,2,3]
@ -20,6 +21,8 @@ subroutine s1()
rVar1 = rCoarray[1,2]
!ERROR: Must have INTEGER type, but is REAL(4)
rVar1 = rCoarray[1,2,3.4]
!ERROR: Must have INTEGER type, but is REAL(4)
iVar1 = smallIntCoarray[3.4]
!ERROR: Must be a scalar value, but is a rank-1 array
rVar1 = rCoarray[1,intArray,3]
! OK