[flang-commits] [flang] 3ed2909 - [flang] Fix crash with alternate returns in modules

Pete Steinfeld via flang-commits flang-commits at lists.llvm.org
Thu Jun 18 08:56:36 PDT 2020


Author: Pete Steinfeld
Date: 2020-06-18T08:56:12-07:00
New Revision: 3ed2909feb34e5b68c6272def7d445a7ca4c5c6f

URL: https://github.com/llvm/llvm-project/commit/3ed2909feb34e5b68c6272def7d445a7ca4c5c6f
DIFF: https://github.com/llvm/llvm-project/commit/3ed2909feb34e5b68c6272def7d445a7ca4c5c6f.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 1f8b9b2552a1..2f813d95f26b 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -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());

diff  --git a/flang/test/Semantics/modfile04.f90 b/flang/test/Semantics/modfile04.f90
index b0a6847b34df..bc4d8d4895ad 100644
--- a/flang/test/Semantics/modfile04.f90
+++ b/flang/test/Semantics/modfile04.f90
@@ -39,6 +39,15 @@ function f4() result(x)
   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 @@ function f4() result(x)
 !complex(4)::x
 !end
 !end
+
+!Expect: m3.mod
+!module m3
+!contains
+!subroutine altreturn(arg1,arg2,*,*)
+!real(4)::arg1
+!real(4)::arg2
+!end
+!end


        


More information about the flang-commits mailing list