[flang-commits] [PATCH] D126436: [flang] Allow forward reference to ENTRY from generic interface

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed May 25 16:48:25 PDT 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

The CreateEntry() function in name resolution needs to allow for the name
of an alternate entry point already having been declared in the outer scope
as the homonymous specific procedure of a generic interface; e.g.,

  interface foo
    module procedure foo
  end interface
  subroutine bar
    entry foo
  end subroutine


https://reviews.llvm.org/D126436

Files:
  flang/lib/Semantics/resolve-names.cpp


Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -3411,10 +3411,21 @@
   if (outer.IsModule() && !attrs.test(Attr::PRIVATE)) {
     attrs.set(Attr::PUBLIC);
   }
-  Symbol &entrySymbol{MakeSymbol(outer, entryName.source, attrs)};
+  Symbol *entrySymbol{FindInScope(outer, entryName.source)};
+  if (entrySymbol) {
+    if (auto *generic{entrySymbol->detailsIf<GenericDetails>()}) {
+      if (auto *specific{generic->specific()}) {
+        // Forward reference to ENTRY from a generic interface
+        entrySymbol = specific;
+        entrySymbol->attrs() |= attrs;
+      }
+    }
+  } else {
+    entrySymbol = &MakeSymbol(outer, entryName.source, attrs);
+  }
   SubprogramDetails entryDetails;
   entryDetails.set_entryScope(currScope());
-  entrySymbol.set(subpFlag);
+  entrySymbol->set(subpFlag);
   if (subpFlag == Symbol::Flag::Function) {
     Symbol *result{nullptr};
     EntityDetails resultDetails;
@@ -3443,11 +3454,12 @@
   if (subpFlag == Symbol::Flag::Subroutine ||
       (distinctResultName && !badResultName)) {
     Symbol &assoc{MakeSymbol(entryName.source)};
-    assoc.set_details(HostAssocDetails{entrySymbol});
+    assoc.set_details(HostAssocDetails{*entrySymbol});
     assoc.set(Symbol::Flag::Subroutine);
   }
-  Resolve(entryName, entrySymbol);
-  entrySymbol.set_details(std::move(entryDetails));
+  Resolve(entryName, *entrySymbol);
+  Details details{std::move(entryDetails)};
+  entrySymbol->set_details(std::move(entryDetails));
 }
 
 void SubprogramVisitor::PostEntryStmt(const parser::EntryStmt &stmt) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126436.432154.patch
Type: text/x-patch
Size: 1697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220525/0e359c05/attachment.bin>


More information about the flang-commits mailing list