diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h --- a/flang/include/flang/Evaluate/tools.h +++ b/flang/include/flang/Evaluate/tools.h @@ -1035,6 +1035,10 @@ class Scope; +// If a symbol represents an ENTRY, return the symbol of the main entry +// point to its subprogram. +const Symbol *GetMainEntry(const 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/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp --- a/flang/lib/Evaluate/tools.cpp +++ b/flang/lib/Evaluate/tools.cpp @@ -1031,6 +1031,19 @@ return symbol; } +const Symbol *GetMainEntry(const Symbol *symbol) { + if (symbol) { + if (const auto *subpDetails{symbol->detailsIf()}) { + if (const Scope * scope{subpDetails->entryScope()}) { + if (const Symbol * main{scope->symbol()}) { + return main; + } + } + } + } + return symbol; +} + bool IsVariableName(const Symbol &original) { const Symbol &symbol{ResolveAssociations(original)}; if (symbol.has()) { @@ -1044,7 +1057,8 @@ } bool IsPureProcedure(const Symbol &original) { - const Symbol &symbol{original.GetUltimate()}; + // An ENTRY is pure if its containing subprogram is + const Symbol &symbol{DEREF(GetMainEntry(&original.GetUltimate()))}; if (const auto *procDetails{symbol.detailsIf()}) { if (const Symbol * procInterface{procDetails->interface().symbol()}) { // procedure component with a pure interface