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

Reply via email to