[flang-commits] [flang] b67984d - [flang] Handle module subprogram with interface in same (sub)module when writing module file

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Jun 16 10:08:53 PDT 2022


Author: Peter Klausler
Date: 2022-06-16T10:08:41-07:00
New Revision: b67984d356272b36ac1ec04c4c844d3b57eeeff5

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

LOG: [flang] Handle module subprogram with interface in same (sub)module when writing module file

There's a few (3) cases where Fortran allows two distinct symbols to have
the same name in the same scope.  Module file output copes with only two of
them.  The third involves a separate module procedure that isn't separate:
both the procedure and its declared interface appear in the same (sub)module.
Fix to ensure that the interface is included in the module file output, so
that the module file reader doesn't suffer a bogus error about a "separate
module procedure without an interface".

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

Added: 
    

Modified: 
    flang/lib/Semantics/mod-file.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index d97b81786e7fe..50ea58077c419 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -419,8 +419,11 @@ static const Attrs subprogramPrefixAttrs{Attr::ELEMENTAL, Attr::IMPURE,
     Attr::MODULE, Attr::NON_RECURSIVE, Attr::PURE, Attr::RECURSIVE};
 
 void ModFileWriter::PutSubprogram(const Symbol &symbol) {
-  auto attrs{symbol.attrs()};
   auto &details{symbol.get<SubprogramDetails>()};
+  if (const Symbol * interface{details.moduleInterface()}) {
+    PutSubprogram(*interface);
+  }
+  auto attrs{symbol.attrs()};
   Attrs bindAttrs{};
   if (attrs.test(Attr::BIND_C)) {
     // bind(c) is a suffix, not prefix
@@ -1092,6 +1095,9 @@ void SubprogramSymbolCollector::Collect() {
         const Symbol *dt{generic->derivedType()};
         needed = needed || (spec && useSet_.count(*spec) > 0) ||
             (dt && useSet_.count(*dt) > 0);
+      } else if (const auto *subp{ultimate.detailsIf<SubprogramDetails>()}) {
+        const Symbol *interface { subp->moduleInterface() };
+        needed = needed || (interface && useSet_.count(*interface) > 0);
       }
       if (needed) {
         need_.push_back(symbol);


        


More information about the flang-commits mailing list