[PATCH] D82096: [flang] Fix crash with alternate returns in modules

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 18 07:34:51 PDT 2020


PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: tskeith, klausler.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld added a project: Flang.
Herald added a reviewer: jdoerfert.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82096

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


Index: flang/test/Semantics/modfile04.f90
===================================================================
--- flang/test/Semantics/modfile04.f90
+++ flang/test/Semantics/modfile04.f90
@@ -39,6 +39,15 @@
   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 @@
 !complex(4)::x
 !end
 !end
+
+!Expect: m3.mod
+!module m3
+!contains
+!subroutine altreturn(arg1,arg2,*,*)
+!real(4)::arg1
+!real(4)::arg2
+!end
+!end
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ flang/lib/Semantics/mod-file.cpp
@@ -322,7 +322,11 @@
     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 @@
   const auto &details{symbol_.get<SubprogramDetails>()};
   isInterface_ = details.isInterface();
   for (const Symbol *dummyArg : details.dummyArgs()) {
-    DoSymbol(DEREF(dummyArg));
+    if (dummyArg) {
+      DoSymbol(DEREF(dummyArg));
+    }
   }
   if (details.isFunction()) {
     DoSymbol(details.result());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82096.271707.patch
Type: text/x-patch
Size: 1391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200618/09a57529/attachment-0001.bin>


More information about the llvm-commits mailing list