[flang-commits] [PATCH] D132686: [flang] Fix module file issue with renamed shadowed specific procedures

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Aug 25 10:56:27 PDT 2022


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

A specific procedure in the list of specific procedures associated with
a generic interface needs to be a symbol that is not inadvertently
resolved to its ultimate symbol in another module when it is also
shadowed by a generic interface of the same name.


https://reviews.llvm.org/D132686

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/modfile50.f90


Index: flang/test/Semantics/modfile50.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/modfile50.f90
@@ -0,0 +1,33 @@
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+module m1
+  interface foo
+    module procedure foo
+  end interface
+ contains
+  subroutine foo
+  end subroutine
+end module
+module m2
+  use m1, bar => foo
+  interface baz
+    module procedure bar ! must not be replaced in module file with "foo"
+  end interface
+end module
+
+!Expect: m1.mod
+!module m1
+!interface foo
+!procedure::foo
+!end interface
+!contains
+!subroutine foo()
+!end
+!end
+
+!Expect: m2.mod
+!module m2
+!use m1,only:bar=>foo
+!interface baz
+!procedure::bar
+!end interface
+!end
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -3105,8 +3105,15 @@
       Say(*name, "Procedure '%s' not found"_err_en_US);
       continue;
     }
-    const Symbol &specific{BypassGeneric(*symbol)};
-    const Symbol &ultimate{specific.GetUltimate()};
+    // Subtlety: when *symbol is a use- or host-association, the specific
+    // procedure that is recorded in the GenericDetails below must be *symbol,
+    // not the specific procedure shadowed by a generic, because that specific
+    // procedure may be a symbol from another module and its name unavailable to
+    // emit to a module file.
+    const Symbol &bypassed{BypassGeneric(*symbol)};
+    const Symbol &specific{
+        symbol == &symbol->GetUltimate() ? bypassed : *symbol};
+    const Symbol &ultimate{bypassed.GetUltimate()};
     if (!ultimate.has<SubprogramDetails>() &&
         !ultimate.has<SubprogramNameDetails>()) {
       Say(*name, "'%s' is not a subprogram"_err_en_US);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132686.455655.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220825/c43cf789/attachment-0001.bin>


More information about the flang-commits mailing list