From: burnus Date: Sun, 28 Feb 2010 16:16:22 +0000 (+0000) Subject: 2010-02-28 Tobias Burnus X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=cf5f0e1cfe810c6f8c3addd2591af144f1367718 2010-02-28 Tobias Burnus PR fortran/43205 * trans-expr.c (is_zero_initializer_p): Move up in the file. (gfc_conv_initializer): Handle zero initializer as special case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157123 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e5d72240c28..88fe30ee7a8 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2010-02-28 Tobias Burnus + + PR fortran/43205 + * trans-expr.c (is_zero_initializer_p): Move up in the file. + (gfc_conv_initializer): Handle zero initializer as special case. + 2010-02-27 Tobias Burnus PR fortran/43185 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index ecb577a2e44..abc2a24318a 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -3910,6 +3910,43 @@ gfc_conv_function_expr (gfc_se * se, gfc_expr * expr) } +/* Determine whether the given EXPR_CONSTANT is a zero initializer. */ + +static bool +is_zero_initializer_p (gfc_expr * expr) +{ + if (expr->expr_type != EXPR_CONSTANT) + return false; + + /* We ignore constants with prescribed memory representations for now. */ + if (expr->representation.string) + return false; + + switch (expr->ts.type) + { + case BT_INTEGER: + return mpz_cmp_si (expr->value.integer, 0) == 0; + + case BT_REAL: + return mpfr_zero_p (expr->value.real) + && MPFR_SIGN (expr->value.real) >= 0; + + case BT_LOGICAL: + return expr->value.logical == 0; + + case BT_COMPLEX: + return mpfr_zero_p (mpc_realref (expr->value.complex)) + && MPFR_SIGN (mpc_realref (expr->value.complex)) >= 0 + && mpfr_zero_p (mpc_imagref (expr->value.complex)) + && MPFR_SIGN (mpc_imagref (expr->value.complex)) >= 0; + + default: + break; + } + return false; +} + + static void gfc_conv_array_constructor_expr (gfc_se * se, gfc_expr * expr) { @@ -3960,6 +3997,9 @@ gfc_conv_initializer (gfc_expr * expr, gfc_typespec * ts, tree type, /* Arrays need special handling. */ if (pointer) return gfc_build_null_descriptor (type); + /* Special case assigning an array to zero. */ + else if (is_zero_initializer_p (expr)) + return build_constructor (type, NULL); else return gfc_conv_array_initializer (type, expr); } @@ -5061,41 +5101,6 @@ gfc_trans_arrayfunc_assign (gfc_expr * expr1, gfc_expr * expr2) return gfc_finish_block (&se.pre); } -/* Determine whether the given EXPR_CONSTANT is a zero initializer. */ - -static bool -is_zero_initializer_p (gfc_expr * expr) -{ - if (expr->expr_type != EXPR_CONSTANT) - return false; - - /* We ignore constants with prescribed memory representations for now. */ - if (expr->representation.string) - return false; - - switch (expr->ts.type) - { - case BT_INTEGER: - return mpz_cmp_si (expr->value.integer, 0) == 0; - - case BT_REAL: - return mpfr_zero_p (expr->value.real) - && MPFR_SIGN (expr->value.real) >= 0; - - case BT_LOGICAL: - return expr->value.logical == 0; - - case BT_COMPLEX: - return mpfr_zero_p (mpc_realref (expr->value.complex)) - && MPFR_SIGN (mpc_realref (expr->value.complex)) >= 0 - && mpfr_zero_p (mpc_imagref (expr->value.complex)) - && MPFR_SIGN (mpc_imagref (expr->value.complex)) >= 0; - - default: - break; - } - return false; -} /* Try to efficiently translate array(:) = 0. Return NULL if this can't be done. */