[flang-commits] [flang] 950a161 - [flang] Fix module file issue with renamed shadowed specific procedures
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Aug 25 15:52:23 PDT 2022
Author: Peter Klausler
Date: 2022-08-25T15:47:52-07:00
New Revision: 950a1618fd6028c76649db1668dc4f97bc69d782
URL: https://github.com/llvm/llvm-project/commit/950a1618fd6028c76649db1668dc4f97bc69d782
DIFF: https://github.com/llvm/llvm-project/commit/950a1618fd6028c76649db1668dc4f97bc69d782.diff
LOG: [flang] Fix module file issue with renamed shadowed specific procedures
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.
Differential Revision: https://reviews.llvm.org/D132686
Added:
flang/test/Semantics/modfile50.f90
Modified:
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b2bc5b4635cd..8f558522ef7a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3124,8 +3124,15 @@ void InterfaceVisitor::ResolveSpecificsInGeneric(Symbol &generic) {
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);
diff --git a/flang/test/Semantics/modfile50.f90 b/flang/test/Semantics/modfile50.f90
new file mode 100644
index 000000000000..366ac0222023
--- /dev/null
+++ b/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
More information about the flang-commits
mailing list