From 88b8971f9cf7c07de72c8b3fe6d4e691bcef7898 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Wed, 24 Aug 2016 19:33:14 +0000 Subject: [PATCH] re PR fortran/77358 ([F08] deferred-length character function returns zero-length string) 2016-08-24 Paul Thomas PR fortran/77358 * resolve.c (resolve_fl_procedure): Use the correct gfc_charlen for deferred character length module procedures. 2016-08-24 Paul Thomas PR fortran/77358 * gfortran.dg/submodule_17.f08: New test. From-SVN: r239740 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/resolve.c | 7 ++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/submodule_17.f08 | 27 ++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/submodule_17.f08 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6dc44e6f035..93eb48ad52b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-08-24 Paul Thomas + + PR fortran/77358 + * resolve.c (resolve_fl_procedure): Use the correct gfc_charlen + for deferred character length module procedures. + 2016-08-23 Fritz Reese * decl.c (gfc_match_structure_decl): Make gfc_structure_id static. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index b7036a82837..0a92efe7784 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11884,6 +11884,13 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag) iface = sym->ts.interface; sym->ts.interface = NULL; + /* Make sure that the result uses the correct charlen for deferred + length results. */ + if (iface && sym->result + && iface->ts.type == BT_CHARACTER + && iface->ts.deferred) + sym->result->ts.u.cl = iface->ts.u.cl; + if (iface == NULL) goto check_formal; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2393eb5ce57..527f2011ac7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-24 Paul Thomas + + PR fortran/77358 + * gfortran.dg/submodule_17.f08: New test. + 2016-08-24 Michael Collison Michael Collison diff --git a/gcc/testsuite/gfortran.dg/submodule_17.f08 b/gcc/testsuite/gfortran.dg/submodule_17.f08 new file mode 100644 index 00000000000..8effef4b417 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_17.f08 @@ -0,0 +1,27 @@ +! { dg-do run } +! +! Tests the fix for PR77358, in which the wrong gfc_charlen was +! being used for the result of 'get'. +! +! Contributed by Damian Rouson +! +module hello_interface + character(len=13) :: string="Hello, world!" + interface + module function get() result(result_string) + character(:), allocatable :: result_string + end function + end interface +end module + +submodule(hello_interface) hello_implementation +contains + module function get() result(result_string) + character(:), allocatable :: result_string + result_string = string + end function +end submodule + + use hello_interface + if (get() .ne. string) call abort +end -- 2.30.2