Skip to content

Commit a34b110

Browse files
[flang] Check for BIND(C) name conflicts with alternate entries (llvm#156563)
Added IsAlternateEntry() and modified IsExternalProcedureDefinition() to also check for alternate entries. (IsExternalProcedureDefinition() is called from CheckHelper::CheckGlobalName(), which checks for duplicate global symbols.) Fixes llvm#62778
1 parent fd8f549 commit a34b110

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,12 @@ class Scope;
15311531
// point to its subprogram.
15321532
const Symbol *GetMainEntry(const Symbol *);
15331533

1534+
inline bool IsAlternateEntry(const Symbol *symbol) {
1535+
// If symbol is not alternate entry symbol, GetMainEntry() returns the same
1536+
// symbol.
1537+
return symbol && GetMainEntry(symbol) != symbol;
1538+
}
1539+
15341540
// These functions are used in Evaluate so they are defined here rather than in
15351541
// Semantics to avoid a link-time dependency on Semantics.
15361542
// All of these apply GetUltimate() or ResolveAssociations() to their arguments.

flang/lib/Semantics/check-declarations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ static bool IsSubprogramDefinition(const Symbol &symbol) {
29502950

29512951
static bool IsExternalProcedureDefinition(const Symbol &symbol) {
29522952
return IsBlockData(symbol) ||
2953-
(IsSubprogramDefinition(symbol) &&
2953+
((IsSubprogramDefinition(symbol) || IsAlternateEntry(&symbol)) &&
29542954
(IsExternal(symbol) || symbol.GetBindName()));
29552955
}
29562956

flang/test/Semantics/bind-c01.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ subroutine foo() bind(c, name="x6")
2929
end subroutine
3030
subroutine foo() bind(c, name="x7")
3131
end subroutine
32+
33+
subroutine entries()
34+
35+
entry e1() bind(C, name="e")
36+
37+
!ERROR: Two entities have the same global name 'e'
38+
entry e2() bind(C, name="e")
39+
end subroutine

0 commit comments

Comments
 (0)