From 7d7212ec2b45c2829dba3bd3319fce109cbe7f01 Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Mon, 22 Aug 2011 14:07:30 +0000 Subject: re PR fortran/50050 (Internal compiler error free_expr0 at expr.c:3709 via gfc_done_2) 2011-08-22 Mikael Morin PR fortran/50050 * gfortran.h (gfc_clear_shape, gfc_free_shape): New prototypes. * expr.c (gfc_clear_shape, gfc_free_shape): New functions. (free_expr0): Re-use gfc_free_shape. * trans-expr.c (gfc_trans_subarray_assign): Ditto. * trans-io.c (transfer_array_component): Ditto. * resolve.c (check_host_association): Ditto. (gfc_expr_to_initialize): Don't force the rank value and free the shape after updating the expression. Recalculate shape and rank. (resolve_where_shape): Re-use gfc_clear_shape. * array.c (gfc_array_ref_shape): Ditto. 2011-08-22 Mikael Morin PR fortran/50050 * gfortran.dg/alloc_comp_initializer_3.f90: New test. From-SVN: r177956 --- gcc/fortran/expr.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'gcc/fortran/expr.c') diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 6d94369..9922094 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -396,6 +396,25 @@ gfc_copy_expr (gfc_expr *p) } +void +gfc_clear_shape (mpz_t *shape, int rank) +{ + int i; + + for (i = 0; i < rank; i++) + mpz_clear (shape[i]); +} + + +void +gfc_free_shape (mpz_t **shape, int rank) +{ + gfc_clear_shape (*shape, rank); + free (*shape); + *shape = NULL; +} + + /* Workhorse function for gfc_free_expr() that frees everything beneath an expression node, but not the node itself. This is useful when we want to simplify a node and replace it with @@ -404,8 +423,6 @@ gfc_copy_expr (gfc_expr *p) static void free_expr0 (gfc_expr *e) { - int n; - switch (e->expr_type) { case EXPR_CONSTANT: @@ -474,12 +491,7 @@ free_expr0 (gfc_expr *e) /* Free a shape array. */ if (e->shape != NULL) - { - for (n = 0; n < e->rank; n++) - mpz_clear (e->shape[n]); - - free (e->shape); - } + gfc_free_shape (&e->shape, e->rank); gfc_free_ref_list (e->ref); -- cgit v1.1