[flang] fix crash found by tim

Original-commit: flang-compiler/f18@c24120d811
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
This commit is contained in:
peter klausler 2019-02-04 13:06:21 -08:00
parent 7f7c44f425
commit 56bf4f8e0f
1 changed files with 16 additions and 19 deletions

View File

@ -428,30 +428,28 @@ static MaybeExpr ApplySubscripts(ExpressionAnalysisContext &context,
std::move(dataRef.u));
}
// Ensure that a whole component reference made to an array of derived type
// does not also reference an array (e.g., A(:)%ARRAY is invalid).
static void CheckUnsubscriptedComponent(
ExpressionAnalysisContext &context, const Component &component) {
int baseRank{component.base().Rank()};
if (baseRank > 0) {
const Symbol &symbol{component.GetLastSymbol()};
int componentRank{symbol.Rank()};
if (componentRank > 0) {
context.Say("reference to whole rank-%d component '%%%s' of "
"rank-%d array of derived type is not allowed"_err_en_US,
componentRank, symbol.name().ToString().data(), baseRank);
}
}
}
// Top-level checks for data references. Unsubscripted whole array references
// get expanded -- e.g., MATRIX becomes MATRIX(:,:).
static MaybeExpr TopLevelChecks(
ExpressionAnalysisContext &context, DataRef &&dataRef) {
bool addSubscripts{false};
if (Component * component{std::get_if<Component>(&dataRef.u)}) {
CheckUnsubscriptedComponent(context, *component);
const Symbol &symbol{component->GetLastSymbol()};
int componentRank{symbol.Rank()};
if (componentRank > 0) {
int baseRank{component->base().Rank()};
if (baseRank > 0) {
context.Say("reference to whole rank-%d component '%%%s' of "
"rank-%d array of derived type is not allowed"_err_en_US,
componentRank, symbol.name().ToString().data(), baseRank);
} else {
addSubscripts = true;
}
}
} else if (const Symbol **symbol{std::get_if<const Symbol *>(&dataRef.u)}) {
addSubscripts = (*symbol)->Rank() > 0;
}
if (dataRef.Rank() > 0) {
if (addSubscripts) {
if (MaybeExpr subscripted{ApplySubscripts(
context, std::move(dataRef), std::vector<Subscript>{})}) {
return subscripted;
@ -1109,7 +1107,6 @@ static MaybeExpr AnalyzeExpr(
static MaybeExpr AnalyzeExpr(ExpressionAnalysisContext &context,
const parser::CoindexedNamedObject &co) {
// TODO: CheckUnsubscriptedComponent or its equivalent
context.Say("TODO: CoindexedNamedObject unimplemented"_err_en_US);
return std::nullopt;
}