Skip to content

Commit 3411263

Browse files
committed
[flang] Ensure USE associations of shadowed procedures are emitted to module files
When a generic interface in a module shadows a procedure of the same name that has been brought into scope via USE association, ensure that that USE association is not lost when the module file is written. Differential Revision: https://reviews.llvm.org/D135207
1 parent de457f6 commit 3411263

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
28292829
} else {
28302830
return;
28312831
}
2832-
} else if (&useUltimate == &BypassGeneric(localUltimate)) {
2832+
} else if (&useUltimate == &BypassGeneric(localUltimate).GetUltimate()) {
28332833
return; // nothing to do; used subprogram is local's specific
28342834
}
28352835
} else if (useGeneric) {
@@ -3230,7 +3230,7 @@ void InterfaceVisitor::CheckGenericProcedures(Symbol &generic) {
32303230
SayDerivedType(generic.name(),
32313231
"Generic interface '%s' may only contain functions due to derived type"
32323232
" with same name"_err_en_US,
3233-
*details.derivedType()->scope());
3233+
*details.derivedType()->GetUltimate().scope());
32343234
}
32353235
generic.set(isFunction ? Symbol::Flag::Function : Symbol::Flag::Subroutine);
32363236
}
@@ -7259,9 +7259,9 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) {
72597259
}
72607260
} else if (ultimate.has<SubprogramDetails>() ||
72617261
ultimate.has<SubprogramNameDetails>()) {
7262-
genericDetails.set_specific(ultimate);
7262+
genericDetails.set_specific(*existing);
72637263
} else if (ultimate.has<DerivedTypeDetails>()) {
7264-
genericDetails.set_derivedType(ultimate);
7264+
genericDetails.set_derivedType(*existing);
72657265
} else {
72667266
SayAlreadyDeclared(symbolName, *existing);
72677267
return;

flang/test/Semantics/modfile52.f90

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
! RUN: %python %S/test_modfile.py %s %flang_fc1
2+
! Ensure that procedure name or derived type name that has been shadowed
3+
! behind a generic interface gets its proper USE statement in a module file.
4+
module m1
5+
contains
6+
subroutine foo
7+
end subroutine
8+
end module
9+
module m2
10+
use m1
11+
interface foo
12+
procedure foo
13+
end interface
14+
end module
15+
module m3
16+
type foo
17+
end type
18+
end module
19+
module m4
20+
use m4
21+
interface foo
22+
procedure bar
23+
end interface
24+
contains
25+
integer function bar
26+
end function
27+
end module
28+
29+
!Expect: m1.mod
30+
!module m1
31+
!contains
32+
!subroutine foo()
33+
!end
34+
!end
35+
36+
!Expect: m2.mod
37+
!module m2
38+
!use m1,only:foo
39+
!interface foo
40+
!procedure::foo
41+
!end interface
42+
!end
43+
44+
!Expect: m3.mod
45+
!module m3
46+
!type::foo
47+
!end type
48+
!end
49+
50+
!Expect: m4.mod
51+
!module m4
52+
!interface foo
53+
!procedure::bar
54+
!end interface
55+
!contains
56+
!function bar()
57+
!integer(4)::bar
58+
!end
59+
!end

0 commit comments

Comments
 (0)