Message ID | 4FF1494A.7000506@net-b.de |
---|---|
State | New |
Headers | show |
On 02.07.2012 09:10, Tobias Burnus wrote: > For some reasons, result variables are walked twice. With > -finit-local-zero their value gets set to 0, either via an inserted > assignment or by adding a initialization (sym->value). > > With -fno-automatic sym->value is also set for result variables, which > later leads to an error. With the patch, that code path is skipped and > an assignment is done. (As the code path is taken twice, twp assignments > are done. I couldn't quickly see why the result variable is resolved > twice.) > > Build and regtested on x86-64-linux. > OK for the trunk? > > Tobias OK. Maybe explain the reasons above in a comment? Thanks for the patch Mikael
2012-07-02 Tobias Burnus <burnus@net-b.de> PR fortran/53818 * resolve.c (apply_default_init_local): Don't create an initializer for a result variable. 2012-07-02 Tobias Burnus <burnus@net-b.de> PR fortran/53818 * gfortran.dg/init_flag_11.f90: New. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 0434e08..c7f14a2 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -10269,7 +10328,7 @@ apply_default_init_local (gfc_symbol *sym) entry, so we just add a static initializer. Note that automatic variables are stack allocated even with -fno-automatic. */ if (sym->attr.save || sym->ns->save_all - || (gfc_option.flag_max_stack_var_size == 0 + || (gfc_option.flag_max_stack_var_size == 0 && !sym->attr.result && (!sym->attr.dimension || !is_non_constant_shape_array (sym)))) { /* Don't clobber an existing initializer! */ --- /dev/null 2012-06-30 08:05:14.091716208 +0200 +++ gcc/gcc/testsuite/gfortran.dg/init_flag_11.f90 2012-07-02 08:58:54.000000000 +0200 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-flags "-finit-local-zero -fno-automatic" +! +! PR fortran/53818 +! +! Contributed by John Moyard +! +logical function testing(date1, date2) result(test) + integer date1, date2 + test = ( (date1 < date2) .or. ( date1==date2 )) +end function testing