[flang] Fix crash with alternate returns in modules

Summary:
We weren't handling the case of subroutines with alternate returns that
are contained in modules.  I changed the code to add an `*` as the name
of the parameter when creating the `.mod` file.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82096
This commit is contained in:
Pete Steinfeld 2020-06-18 07:05:08 -07:00
parent 2d865ccbd8
commit 3ed2909feb
2 changed files with 26 additions and 2 deletions

View File

@ -322,7 +322,11 @@ void ModFileWriter::PutSubprogram(const Symbol &symbol) {
if (n++ > 0) {
os << ',';
}
os << dummy->name();
if (dummy) {
os << dummy->name();
} else {
os << "*";
}
}
os << ')';
PutAttrs(os, bindAttrs, details.bindName(), " "s, ""s);
@ -825,7 +829,9 @@ void SubprogramSymbolCollector::Collect() {
const auto &details{symbol_.get<SubprogramDetails>()};
isInterface_ = details.isInterface();
for (const Symbol *dummyArg : details.dummyArgs()) {
DoSymbol(DEREF(dummyArg));
if (dummyArg) {
DoSymbol(*dummyArg);
}
}
if (details.isFunction()) {
DoSymbol(details.result());

View File

@ -39,6 +39,15 @@ contains
end
end
! Module with a subroutine with alternate returns
module m3
contains
subroutine altReturn(arg1, arg2, *, *)
real :: arg1
real :: arg2
end subroutine
end module m3
!Expect: m1.mod
!module m1
!type::t
@ -73,3 +82,12 @@ end
!complex(4)::x
!end
!end
!Expect: m3.mod
!module m3
!contains
!subroutine altreturn(arg1,arg2,*,*)
!real(4)::arg1
!real(4)::arg2
!end
!end