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 @@ -7633,9 +7633,13 @@ static bool IsLocallyImplicitGlobalSymbol( const Symbol &symbol, const parser::Name &localName) { - return symbol.owner().IsGlobal() && - (!symbol.scope() || - !symbol.scope()->sourceRange().Contains(localName.source)); + if (symbol.owner().IsGlobal()) { + const auto *subp{symbol.detailsIf()}; + const Scope *scope{ + subp && subp->entryScope() ? subp->entryScope() : symbol.scope()}; + return !(scope && scope->sourceRange().Contains(localName.source)); + } + return false; } static bool TypesMismatchIfNonNull( diff --git a/flang/test/Semantics/global01.f90 b/flang/test/Semantics/global01.f90 --- a/flang/test/Semantics/global01.f90 +++ b/flang/test/Semantics/global01.f90 @@ -21,6 +21,13 @@ integer, intent(in) :: x end subroutine +! Regression check: don't emit bogus "Implicit declaration of function 'global7' has a different result type than in previous declaration" +recursive function global6() + integer global6, z, n +entry global7(n) result(z) + if (n > 0) z = global7(n-1) +end function + program test interface !WARNING: The global subprogram 'global1' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object types: INTEGER(4) vs REAL(4)) @@ -40,6 +47,11 @@ pure subroutine global5(x) integer, intent(in) :: x end subroutine + function global6() + integer global6 + end function + function global7(n) result(z) + integer n, z + end function end interface end -