From fe588aff566fde9a8fbc7a9a89ab4205999a8c53 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Thu, 28 Feb 2019 09:53:49 -0800 Subject: [PATCH] [flang] Fix bug handling function prefix type This showed up in procinterface01. A function can have more than one PrefixSpec (e.g. `real elemental f()`). We need to ignore that ones that aren't types. Also, process the type after the ImplicitPart rather than after the SpecificationPart. The type of the function result variable could be accessed between those places. Original-commit: flang-compiler/f18@df85eedb925b6f8739d6f6ccd9820ff5d9e4f4c5 Reviewed-on: https://github.com/flang-compiler/f18/pull/305 --- flang/lib/semantics/resolve-names.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 9e462ad..15b5ca3 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -609,11 +609,11 @@ public: void Post(const parser::SeparateModuleSubprogram &); bool Pre(const parser::Suffix &); bool Pre(const parser::PrefixSpec &); + void Post(const parser::ImplicitPart &); protected: // Set when we see a stmt function that is really an array element assignment bool badStmtFuncFound_{false}; - void HandleFunctionPrefixType(); private: // Info about the current function: parse tree of the type in the PrefixSpec; @@ -2196,12 +2196,17 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) { bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) { // Save this to process after UseStmt and ImplicitPart - funcInfo_.parsedType = std::get_if(&x.u); - funcInfo_.source = currStmtSource(); - return funcInfo_.parsedType == nullptr; + if (const auto *parsedType{std::get_if(&x.u)}) { + funcInfo_.parsedType = parsedType; + funcInfo_.source = currStmtSource(); + return false; + } else { + return true; + } } -void SubprogramVisitor::HandleFunctionPrefixType() { +void SubprogramVisitor::Post(const parser::ImplicitPart &) { + // If the function has a type in the prefix, process it now if (funcInfo_.parsedType) { messageHandler().set_currStmtSource(funcInfo_.source); if (const auto *type{ProcessTypeSpec(*funcInfo_.parsedType)}) { @@ -4485,7 +4490,6 @@ static bool NeedsExplicitType(const Symbol &symbol) { void ResolveNamesVisitor::Post(const parser::SpecificationPart &) { badStmtFuncFound_ = false; CheckImports(); - HandleFunctionPrefixType(); bool inModule{currScope().kind() == Scope::Kind::Module}; for (auto &pair : currScope()) { auto &symbol{*pair.second}; -- 2.7.4