Skip to content

release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) #133223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release/20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flang/lib/Evaluate/formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ llvm::raw_ostream &Constant<Type<TypeCategory::Character, KIND>>::AsFortran(
llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const Symbol &symbol,
std::optional<parser::CharBlock> name = std::nullopt) {
const auto &renamings{symbol.owner().context().moduleFileOutputRenamings()};
if (auto iter{renamings.find(&symbol)}; iter != renamings.end()) {
if (auto iter{renamings.find(&symbol.GetUltimate())};
iter != renamings.end()) {
return o << iter->second.ToString();
} else if (name) {
return o << name->ToString();
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/mod-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void ModFileWriter::PrepareRenamings(const Scope &scope) {
uses_ << DEREF(sMod->symbol()).name() << ",only:";
if (rename != s->name()) {
uses_ << rename << "=>";
renamings.emplace(&*s, rename);
renamings.emplace(&s->GetUltimate(), rename);
}
uses_ << s->name() << '\n';
useExtraAttrs_ << "private::" << rename << '\n';
Expand Down
85 changes: 85 additions & 0 deletions flang/test/Semantics/bug132435.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
! RUN: %python %S/test_modfile.py %s %flang_fc1
module m1
type foo
integer :: c1 = 123
end type
end

module m2
use m1, only: foo
type baz
type(foo) :: d = foo()
end type
type bar
type(baz) :: e = baz()
end type
end

module m3
use m1, only: m1foo => foo
type foo
type(m1foo), private :: c2 = m1foo()
end type
end

module m4
use m2, only: m3foo => foo
type foo
type(m3foo), private :: c3 = m3foo()
end type
end

module m5
use m2, only: m2bar => bar
use m4, only: foo
type blah
type(m2bar) :: f = m2bar()
end type
end

!Expect: m1.mod
!module m1
!type::foo
!integer(4)::c1=123_4
!end type
!end

!Expect: m2.mod
!module m2
!use m1,only:foo
!type::baz
!type(foo)::d=foo(c1=123_4)
!end type
!type::bar
!type(baz)::e=baz(d=foo(c1=123_4))
!end type
!end

!Expect: m3.mod
!module m3
!use m1,only:m1foo=>foo
!type::foo
!type(m1foo),private::c2=m1foo(c1=123_4)
!end type
!end

!Expect: m4.mod
!module m4
!use m2,only:m3foo=>foo
!type::foo
!type(m3foo),private::c3=m3foo(c1=123_4)
!end type
!end

!Expect: m5.mod
!module m5
!use m2,only:m2$foo=>foo
!use m2,only:baz
!use m2,only:m2bar=>bar
!use m4,only:foo
!private::m2$foo
!private::baz
!type::blah
!type(m2bar)::f=m2bar(e=baz(d=m2$foo(c1=123_4)))
!end type
!end
Loading