]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Fortran] Fix result-variable handling of MODULE PROCEDURE (PR94348)
authorTobias Burnus <tobias@codesourcery.com>
Mon, 30 Mar 2020 07:23:12 +0000 (09:23 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 30 Mar 2020 07:23:12 +0000 (09:23 +0200)
Backport from mainline
2020-03-28  Tobias Burnus  <tobias@codesourcery.com>

PR fortran/94348
* decl.c (gfc_match_submod_proc): Add result var to the
proc's namespace.

PR fortran/94348
* gfortran.dg/module_procedure_3.f90: New.

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/module_procedure_3.f90 [new file with mode: 0644]

index 503b385d79c6e15cf0d3f10f36a20a7b6b7fd405..99106cc39a08fa0c635016953067b71e3f991dfa 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-28  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2020-03-28  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/94348
+       * decl.c (gfc_match_submod_proc): Add result var to the
+       proc's namespace.
+
 2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
 
        Backport from master
index abff4af9f673035e33856e893542749c2017a02b..0291e248bb36bf3aa1cf80be02bf251568d87d02 100644 (file)
@@ -9602,13 +9602,20 @@ gfc_match_submod_proc (void)
   if (get_proc_name (name, &sym, false))
     return MATCH_ERROR;
 
-  /* Make sure that the result field is appropriately filled, even though
-     the result symbol will be replaced later on.  */
+  /* Make sure that the result field is appropriately filled.  */
   if (sym->tlink && sym->tlink->attr.function)
     {
-      if (sym->tlink->result
-         && sym->tlink->result != sym->tlink)
-       sym->result= sym->tlink->result;
+      if (sym->tlink->result && sym->tlink->result != sym->tlink)
+       {
+         sym->result = sym->tlink->result;
+         if (!sym->result->attr.use_assoc)
+           {
+             gfc_symtree *st = gfc_new_symtree (&gfc_current_ns->sym_root,
+                                                sym->result->name);
+             st->n.sym = sym->result;
+             sym->result->refs++;
+           }
+       }
       else
        sym->result = sym;
     }
index e4d99050bcfd568905c933ddabf55ea7b02b7246..71686c72a33288f6bdb944af5dd618a6e4ffef97 100644 (file)
@@ -1,3 +1,11 @@
+2020-03-28  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2020-03-28  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/94348
+       * gfortran.dg/module_procedure_3.f90: New.
+
 2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
 
        Backport from master
@@ -19,7 +27,7 @@
 2020-03-24  Tamar Christina  <tamar.christina@arm.com>
 
        PR target/94052
-        * g++.target/aarch64/pr94052.C: New test.
+       * g++.target/aarch64/pr94052.C: New test.
 
 2020-03-24  Bin Cheng  <bin.cheng@linux.alibaba.com>
 
diff --git a/gcc/testsuite/gfortran.dg/module_procedure_3.f90 b/gcc/testsuite/gfortran.dg/module_procedure_3.f90
new file mode 100644 (file)
index 0000000..50a83d9
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do run }
+!
+! PR fortran/94348
+!
+! Contributed by Damian Rouson
+
+module foo_module
+  implicit none
+
+  interface
+     module function foo() result(bar)
+       implicit none
+       integer bar
+     end function
+  end interface
+
+contains
+  module procedure foo
+    bar = 5
+  end procedure
+end module
+
+program main
+  use foo_module
+  implicit none
+  if (foo() /= 5) stop 1
+end program main