From: peter klausler Date: Tue, 10 Nov 2020 23:10:48 +0000 (-0800) Subject: [flang] Use IMPLICIT from scope of external function reference X-Git-Tag: llvmorg-13-init~6364 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d5b850751789531d9c47e1ccc18f1ac8f9bac7a;p=platform%2Fupstream%2Fllvm.git [flang] Use IMPLICIT from scope of external function reference Implicitly typed references to external functions are applying the IMPLICIT typing rules of the global scope in which their symbols were created, not the IMPLICIT typing rules in force in the scope from which they were referenced. Differential revision: https://reviews.llvm.org/D91214 --- diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 5f17aab..f2b88ba 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -594,7 +594,7 @@ public: protected: // Apply the implicit type rules to this symbol. void ApplyImplicitRules(Symbol &); - const DeclTypeSpec *GetImplicitType(Symbol &); + const DeclTypeSpec *GetImplicitType(Symbol &, const Scope &); bool ConvertToObjectEntity(Symbol &); bool ConvertToProcEntity(Symbol &); @@ -2111,7 +2111,12 @@ static bool NeedsType(const Symbol &symbol) { void ScopeHandler::ApplyImplicitRules(Symbol &symbol) { if (NeedsType(symbol)) { - if (const DeclTypeSpec * type{GetImplicitType(symbol)}) { + const Scope *scope{&symbol.owner()}; + if (scope->IsGlobal()) { + scope = &currScope(); + } + if (const DeclTypeSpec * + type{GetImplicitType(symbol, GetInclusiveScope(*scope))}) { symbol.set(Symbol::Flag::Implicit); symbol.SetType(*type); return; @@ -2137,9 +2142,9 @@ void ScopeHandler::ApplyImplicitRules(Symbol &symbol) { } } -const DeclTypeSpec *ScopeHandler::GetImplicitType(Symbol &symbol) { - const auto *type{implicitRulesMap_->at(&GetInclusiveScope(symbol.owner())) - .GetType(symbol.name())}; +const DeclTypeSpec *ScopeHandler::GetImplicitType( + Symbol &symbol, const Scope &scope) { + const auto *type{implicitRulesMap_->at(&scope).GetType(symbol.name())}; if (type) { if (const DerivedTypeSpec * derived{type->AsDerived()}) { // Resolve any forward-referenced derived type; a quick no-op else.