From 3b7b2f56d5d433b865c0a7668b53bb6c10f80c12 Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Thu, 8 Aug 2019 03:46:14 -0700 Subject: [PATCH] [flang] Answer PR 631 comments: - Create a function `IsFunctionResult(const Symbol &)` in lib/semantics/tools.h. - style edit in weird var definition style. Original-commit: flang-compiler/f18@15e3f87b40345765ac500e5f8c1412c31d4e2658 Reviewed-on: https://github.com/flang-compiler/f18/pull/631 Tree-same-pre-rewrite: false --- flang/lib/semantics/expression.cc | 6 +++--- flang/lib/semantics/tools.cc | 12 ++++++++---- flang/lib/semantics/tools.h | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index 49d05b6..0472125 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -1840,9 +1840,9 @@ static void CheckFuncRefToArrayElementRefHasSubscripts( if (std::get>(funcRef.v.t).empty()) { auto &proc{std::get(funcRef.v.t)}; const auto *name{std::get_if(&proc.u)}; - name = {name - ? name - : &std::get(proc.u).v.thing.component}; + if (name == nullptr) { + name = &std::get(proc.u).v.thing.component; + } auto &msg{context.Say(funcRef.v.source, "Reference to array '%s' with empty subscript list"_err_en_US, name->source)}; diff --git a/flang/lib/semantics/tools.cc b/flang/lib/semantics/tools.cc index 19146ee..98e70a2 100644 --- a/flang/lib/semantics/tools.cc +++ b/flang/lib/semantics/tools.cc @@ -937,11 +937,15 @@ const Symbol *FindUltimateComponent(const DerivedTypeSpec &derived, return nullptr; } -bool IsFunctionResultWithSameNameAsFunction(const Symbol &symbol) { - if ((symbol.has() && - symbol.get().isFuncResult()) || +bool IsFunctionResult(const Symbol &symbol) { + return (symbol.has() && + symbol.get().isFuncResult()) || (symbol.has() && - symbol.get().isFuncResult())) { + symbol.get().isFuncResult()); +} + +bool IsFunctionResultWithSameNameAsFunction(const Symbol &symbol) { + if (IsFunctionResult(symbol)) { if (const Symbol * function{symbol.owner().symbol()}) { return symbol.name() == function->name(); } diff --git a/flang/lib/semantics/tools.h b/flang/lib/semantics/tools.h index 0105518..267aaef 100644 --- a/flang/lib/semantics/tools.h +++ b/flang/lib/semantics/tools.h @@ -62,6 +62,8 @@ bool IsProcedure(const Symbol &); bool IsProcName(const Symbol &symbol); // proc-name bool IsVariableName(const Symbol &symbol); // variable-name bool IsProcedurePointer(const Symbol &); +bool IsFunctionResult(const Symbol &); +bool IsFunctionResultWithSameNameAsFunction(const Symbol &); bool IsExtensibleType(const DerivedTypeSpec *); // Is this a derived type from module with this name? bool IsDerivedTypeFromModule( -- 2.7.4