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 @@ -1892,7 +1892,10 @@ auto pair{bindC_.emplace(*name, symbol)}; if (!pair.second) { const Symbol &other{*pair.first->second}; - if (DefinesBindCName(other) && !context_.HasError(other)) { + // Two common blocks with the same name can have the same BIND(C) name. + if ((!symbol.has() || + symbol.name() != other.name()) && + DefinesBindCName(other) && !context_.HasError(other)) { if (auto *msg{messages_.Say(symbol.name(), "Two symbols have the same BIND(C) name '%s'"_err_en_US, *name)}) { diff --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90 --- a/flang/test/Semantics/declarations03.f90 +++ b/flang/test/Semantics/declarations03.f90 @@ -48,3 +48,24 @@ integer, bind(c, name="ss2") :: s5 end + +subroutine common1() + real :: x + common /com/ x + bind(c, name='xcom') /com/ ! no error +end subroutine + +subroutine common2() + real :: x + common /com/ x + bind(c, name='xcom') /com/ ! no error +end subroutine + +module a + integer, bind(c, name="int") :: i +end module + +module b + !ERROR: Two symbols have the same BIND(C) name 'int' + integer, bind(c, name="int") :: i +end module