diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h index 225e1a77f041b..5f2f199e778c7 100644 --- a/flang/include/flang/Evaluate/tools.h +++ b/flang/include/flang/Evaluate/tools.h @@ -1531,6 +1531,12 @@ class Scope; // point to its subprogram. const Symbol *GetMainEntry(const Symbol *); +inline bool IsAlternateEntry(const Symbol *symbol) { + // If symbol is not alternate entry symbol, GetMainEntry() returns the same + // symbol. + return symbol && GetMainEntry(symbol) != symbol; +} + // These functions are used in Evaluate so they are defined here rather than in // Semantics to avoid a link-time dependency on Semantics. // All of these apply GetUltimate() or ResolveAssociations() to their arguments. diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index b9f5737468ff8..84edcebc64973 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -2950,7 +2950,7 @@ static bool IsSubprogramDefinition(const Symbol &symbol) { static bool IsExternalProcedureDefinition(const Symbol &symbol) { return IsBlockData(symbol) || - (IsSubprogramDefinition(symbol) && + ((IsSubprogramDefinition(symbol) || IsAlternateEntry(&symbol)) && (IsExternal(symbol) || symbol.GetBindName())); } diff --git a/flang/test/Semantics/bind-c01.f90 b/flang/test/Semantics/bind-c01.f90 index f0546b3eb068c..79d53677abc9d 100644 --- a/flang/test/Semantics/bind-c01.f90 +++ b/flang/test/Semantics/bind-c01.f90 @@ -29,3 +29,11 @@ subroutine foo() bind(c, name="x6") end subroutine subroutine foo() bind(c, name="x7") end subroutine + +subroutine entries() + +entry e1() bind(C, name="e") + +!ERROR: Two entities have the same global name 'e' +entry e2() bind(C, name="e") +end subroutine