Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flang/include/flang/Evaluate/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,12 @@ class Scope;
// point to its subprogram.
const Symbol *GetMainEntry(const Symbol *);

inline bool IsAlternateEntry(const Symbol *symbol) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more clear to implement these in the opposite way, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean have IsAlternateEntry(&symbol) be primary and IsAlternateEntry(*symbol) call it? I started it that way, but because GetMainEntry() returns a pointer, it looked somewhat less clean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only have one call site, then you don't need both APIs (yet).

I have been slowing converting tools like this -- ones with reasonable results for absent (null) pointer arguments -- into pointer-only forms, as I run across hem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I only left IsAlternateEntry() that accepts the pointer, because it still looks cleaner to me.

// 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.
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
8 changes: 8 additions & 0 deletions flang/test/Semantics/bind-c01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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