re PR fortran/51800 (Error: Automatic array 'dummy' at (1) cannot have an initializer)

2012-01-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51800
        * resolve.c (build_default_init_expr): Also initialize
        nonconstant-length strings with -finit-character=<n>.

2012-01-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51800
        * gfortran.dg/init_flag_8.f90: New.
        * gfortran.dg/init_flag_9.f90: New.

From-SVN: r183180
This commit is contained in:
Tobias Burnus 2012-01-14 13:05:59 +01:00 committed by Tobias Burnus
parent 74250065e2
commit 068ed5e0e1
5 changed files with 70 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2012-01-14 Tobias Burnus <burnus@net-b.de>
PR fortran/51800
* resolve.c (build_default_init_expr): Also initialize
nonconstant-length strings with -finit-character=<n>.
2011-01-14 Tobias Burnus <burnus@net-b.de>
PR fortran/51816

View File

@ -10143,6 +10143,26 @@ build_default_init_expr (gfc_symbol *sym)
gfc_free_expr (init_expr);
init_expr = NULL;
}
if (!init_expr && gfc_option.flag_init_character == GFC_INIT_CHARACTER_ON
&& sym->ts.u.cl->length)
{
gfc_actual_arglist *arg;
init_expr = gfc_get_expr ();
init_expr->where = sym->declared_at;
init_expr->ts = sym->ts;
init_expr->expr_type = EXPR_FUNCTION;
init_expr->value.function.isym =
gfc_intrinsic_function_by_id (GFC_ISYM_REPEAT);
init_expr->value.function.name = "repeat";
arg = gfc_get_actual_arglist ();
arg->expr = gfc_get_character_expr (sym->ts.kind, &sym->declared_at,
NULL, 1);
arg->expr->value.character.string[0]
= gfc_option.flag_init_character_value;
arg->next = gfc_get_actual_arglist ();
arg->next->expr = gfc_copy_expr (sym->ts.u.cl->length);
init_expr->value.function.actual = arg;
}
break;
default:
@ -10169,10 +10189,12 @@ apply_default_init_local (gfc_symbol *sym)
if (init == NULL)
return;
/* For saved variables, we don't want to add an initializer at
function entry, so we just add a static initializer. */
/* For saved variables, we don't want to add an initializer at function
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.dimension || !is_non_constant_shape_array (sym))))
{
/* Don't clobber an existing initializer! */
gcc_assert (sym->value == NULL);

View File

@ -1,3 +1,9 @@
2012-01-14 Tobias Burnus <burnus@net-b.de>
PR fortran/51800
* gfortran.dg/init_flag_8.f90: New.
* gfortran.dg/init_flag_9.f90: New.
2011-01-14 Tobias Burnus <burnus@net-b.de>
PR fortran/51816

View File

@ -0,0 +1,18 @@
! { dg-do compile }
! { dg-options "-fno-automatic -finit-local-zero" }
!
! PR fortran/51800
!
! Contributed by Mario Baumann
!
SUBROUTINE FOO( N, A )
IMPLICIT NONE
INTEGER :: N
INTEGER :: A(1:N)
INTEGER :: J
INTEGER :: DUMMY(1:N)
DO J=1,N
DUMMY(J) = 0
A(J) = DUMMY(J)
END DO
END SUBROUTINE FOO

View File

@ -0,0 +1,15 @@
! { dg-do run }
! { dg-options "-finit-character=89" }
!
! PR fortran/51800
!
subroutine foo(n)
character(len=n) :: str
! print *, str
if (str /= repeat ('Y', n)) call abort()
end subroutine foo
call foo(3)
call foo(10)
end