diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -2038,7 +2038,14 @@ Scope *ScopeHandler::GetHostProcedure() { Scope &parent{InclusiveScope().parent()}; - return parent.kind() == Scope::Kind::Subprogram ? &parent : nullptr; + switch (parent.kind()) { + case Scope::Kind::Subprogram: + return &parent; + case Scope::Kind::MainProgram: + return &parent; + default: + return nullptr; + } } Scope &ScopeHandler::NonDerivedTypeScope() {