From: Tobias Burnus Date: Sat, 28 Mar 2020 13:01:57 +0000 (+0100) Subject: [Fortran] Fix result-variable handling of MODULE PROCEDURE (PR94348) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3fb7f2fbd5f109786922deb5af8fd8dd594a7ba6;p=gcc.git [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 --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 + + PR fortran/94348 + * decl.c (gfc_match_submod_proc): Add result var to the + proc's namespace. + 2020-03-27 Tobias Burnus 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 + + PR fortran/94348 + * gfortran.dg/module_procedure_3.f90: New. + 2020-03-28 Patrick Palka 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