[gcc/devel/ranger] [Fortran] Fix result-variable handling of MODULE PROCEDURE (PR94348)
Aldy Hernandez
aldyh@gcc.gnu.org
Wed Jun 17 20:01:46 GMT 2020
https://gcc.gnu.org/g:3fb7f2fbd5f109786922deb5af8fd8dd594a7ba6
commit 3fb7f2fbd5f109786922deb5af8fd8dd594a7ba6
Author: Tobias Burnus <tobias@codesourcery.com>
Date: Sat Mar 28 14:01:57 2020 +0100
[Fortran] Fix result-variable handling of MODULE PROCEDURE (PR94348)
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.
Diff:
---
gcc/fortran/ChangeLog | 6 ++++++
gcc/fortran/decl.c | 17 ++++++++++-----
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gfortran.dg/module_procedure_3.f90 | 27 ++++++++++++++++++++++++
4 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 02f0141bebf..48bf8bfc7fa 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+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-27 Tobias Burnus <tobias@codesourcery.com>
PR fortran/93957
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 2f458c4faac..79c951003ad 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -9699,13 +9699,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;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3422550ae02..92f161f197a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-28 Tobias Burnus <tobias@codesourcery.com>
+
+ PR fortran/94348
+ * gfortran.dg/module_procedure_3.f90: New.
+
2020-03-28 Patrick Palka <ppalka@redhat.com>
PR c++/94306
diff --git a/gcc/testsuite/gfortran.dg/module_procedure_3.f90 b/gcc/testsuite/gfortran.dg/module_procedure_3.f90
new file mode 100644
index 00000000000..50a83d9e5b1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/module_procedure_3.f90
@@ -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
More information about the Gcc-cvs
mailing list