This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Fortran, PR58586, v3] ICE with derived type with allocatable component passed by value
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: Andre Vehreschild <vehre at gmx dot de>
- Cc: GCC-Patches-ML <gcc-patches at gcc dot gnu dot org>, GCC-Fortran-ML <fortran at gcc dot gnu dot org>
- Date: Thu, 07 May 2015 12:14:59 +0200
- Subject: Re: [Patch, Fortran, PR58586, v3] ICE with derived type with allocatable component passed by value
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sfrmc.priv.atos.fr; dkim=none (no signature); dkim-adsp=none (no policy) header dot from=mikael dot morin at sfr dot fr
- References: <20150415200304 dot 7101aca9 at gmx dot de> <55337CF3 dot 9010002 at sfr dot fr> <20150423200052 dot 2e7a1311 at gmx dot de> <553CBC80 dot 2050208 at sfr dot fr> <20150505110026 dot 7ecbc229 at gmx dot de>
Hello,
Le 05/05/2015 11:00, Andre Vehreschild a Ãcrit :
> diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
> index 4c18920..0b63175 100644
> --- a/gcc/fortran/trans-decl.c
> +++ b/gcc/fortran/trans-decl.c
> @@ -2158,6 +2158,8 @@ build_function_decl (gfc_symbol * sym, bool global)
> gfc_set_decl_assembler_name (fndecl, gfc_sym_mangled_function_id (sym));
>
> sym->backend_decl = fndecl;
> + if (sym == sym->result && !sym->result->backend_decl)
> + sym->result->backend_decl = result_decl;
Something is seriously misbehaving if the condition is true, and setting
sym->backend_decl to result_decl doesn't seem any better than keeping it
NULL.
So, please remove this change
> }
>
>
> @@ -5898,8 +5900,21 @@ gfc_generate_function_code (gfc_namespace * ns)
>
> if (TREE_TYPE (DECL_RESULT (fndecl)) != void_type_node)
> {
> + bool artificial_result_decl = false;
> tree result = get_proc_result (sym);
>
> + /* Make sure that a function returning an object with
> + alloc/pointer_components always has a result, where at least
> + the allocatable/pointer components are set to zero. */
> + if (result == NULL_TREE && sym->attr.function
> + && sym->ts.type == BT_DERIVED
> + && (sym->ts.u.derived->attr.alloc_comp
> + || sym->ts.u.derived->attr.pointer_comp))
> + {
> + artificial_result_decl = true;
> + result = gfc_get_fake_result_decl (sym, 0);
> + }
I expect the "fake" result decl to be needed in more cases.
For example, if type is BT_CLASS.
Here is a variant of alloc_comp_class_4.f03:c_init for such a case.
class(c) function c_init2()
allocatable :: c_init2
end function
or even without class:
type(t) function t_init()
allocatable :: t_init
end function
for some any type t.
So, remove the check for alloc_comp/pointer_comp and permit BT_CLASS.
One minor thing, check sym->result's type and attribute instead of sym's
here. It should not make a difference, but I think it's more correct.
The rest looks good.
The patch is OK with the suggested changes above. Thanks.
I don't think the test functions above work well enough to be
incorporated in a testcase for now.
Mikael