From 56bf4f8e0f7884dd81bf79ffa2517788eba4b8c6 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Mon, 4 Feb 2019 13:06:21 -0800 Subject: [PATCH] [flang] fix crash found by tim Original-commit: flang-compiler/f18@c24120d8116c58ceaed6e70fb1cedeb517ddb4a4 Reviewed-on: https://github.com/flang-compiler/f18/pull/271 --- flang/lib/semantics/expression.cc | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index c0dda78..0984ae3 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -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(&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(&dataRef.u)}) { + addSubscripts = (*symbol)->Rank() > 0; } - if (dataRef.Rank() > 0) { + if (addSubscripts) { if (MaybeExpr subscripted{ApplySubscripts( context, std::move(dataRef), std::vector{})}) { 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; } -- 2.7.4