diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -2552,7 +2552,8 @@ } else { const std::string *bindC{symbol.GetBindName()}; if (symbol.has() || - IsExternalProcedureDefinition(symbol)) { + IsExternalProcedureDefinition(symbol) || + (symbol.owner().IsGlobal() && IsExternal(symbol))) { return bindC ? *bindC : symbol.name().ToString(); } else if (bindC && (symbol.has() || IsModuleProcedure(symbol))) { diff --git a/flang/test/Semantics/declarations04.f90 b/flang/test/Semantics/declarations04.f90 --- a/flang/test/Semantics/declarations04.f90 +++ b/flang/test/Semantics/declarations04.f90 @@ -23,3 +23,9 @@ !PORTABILITY: Global name 'ext4' conflicts with a module common /ext4/ x end + +subroutine s + !ERROR: Two entities have the same global name 'foo' + common /foo/n + call foo +end