[flang] Fix crash with alternate returns in modules
authorPete Steinfeld <psteinfeld@nvidia.com>
Thu, 18 Jun 2020 14:05:08 +0000 (07:05 -0700)
committerPete Steinfeld <psteinfeld@nvidia.com>
Thu, 18 Jun 2020 15:56:12 +0000 (08:56 -0700)
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

flang/lib/Semantics/mod-file.cpp
flang/test/Semantics/modfile04.f90

index 1f8b9b2..2f813d9 100644 (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());
index b0a6847..bc4d8d4 100644 (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