[flang-commits] [flang] ece1706 - [flang] Handle ENTRY names in IsPureProcedure() predicate

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Nov 12 13:21:26 PST 2021


Author: Peter Klausler
Date: 2021-11-12T13:21:18-08:00
New Revision: ece17064b592db70a56ef7e4e750d0fe589014f2

URL: https://github.com/llvm/llvm-project/commit/ece17064b592db70a56ef7e4e750d0fe589014f2
DIFF: https://github.com/llvm/llvm-project/commit/ece17064b592db70a56ef7e4e750d0fe589014f2.diff

LOG: [flang] Handle ENTRY names in IsPureProcedure() predicate

Fortran defines an ENTRY point name as being pure if its enclosing
subprogram scope defines a pure procedure.

Differential Revision: https://reviews.llvm.org/D113711

Added: 
    

Modified: 
    flang/include/flang/Evaluate/tools.h
    flang/lib/Evaluate/tools.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index ff4d3155b7c4..a8e25df4e5f6 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1035,6 +1035,10 @@ namespace Fortran::semantics {
 
 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
index a3f177b1bb34..722d0c06b12e 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1031,6 +1031,19 @@ const Symbol &GetAssociationRoot(const Symbol &original) {
   return symbol;
 }
 
+const Symbol *GetMainEntry(const Symbol *symbol) {
+  if (symbol) {
+    if (const auto *subpDetails{symbol->detailsIf<SubprogramDetails>()}) {
+      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<ObjectEntityDetails>()) {
@@ -1044,7 +1057,8 @@ bool IsVariableName(const Symbol &original) {
 }
 
 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<ProcEntityDetails>()}) {
     if (const Symbol * procInterface{procDetails->interface().symbol()}) {
       // procedure component with a pure interface


        


More information about the flang-commits mailing list