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 <mikael.morin@gcc.gnu.org>
PR fortran/50050
* gfortran.dg/alloc_comp_initializer_3.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177956
138bc75d-0d04-0410-961f-
82ee72b054a4
+2011-08-22 Mikael Morin <mikael.morin@gcc.gnu.org>
+
+ 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-21 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/47659
* dependency.c (gfc_dep_compare_expr): Add new result value "-3".
(gfc_check_element_vs_section,gfc_check_element_vs_element): Handle
result value "-3".
- * frontend-passes.c (optimize_comparison): Ditto.
+ * frontend-passes.c (optimize_comparison): Ditto.
* interface.c (gfc_check_typebound_override): Ditto.
2011-08-19 Mikael Morin <mikael.morin@sfr.fr>
}
cleanup:
- for (d--; d >= 0; d--)
- mpz_clear (shape[d]);
-
+ gfc_clear_shape (shape, d);
return FAILURE;
}
}
+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
static void
free_expr0 (gfc_expr *e)
{
- int n;
-
switch (e->expr_type)
{
case EXPR_CONSTANT:
/* 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);
gfc_expr *gfc_get_logical_expr (int, locus *, bool);
gfc_expr *gfc_get_iokind_expr (locus *, io_kind);
+void gfc_clear_shape (mpz_t *shape, int rank);
+void gfc_free_shape (mpz_t **shape, int rank);
void gfc_free_expr (gfc_expr *);
void gfc_replace_expr (gfc_expr *, gfc_expr *);
mpz_t *gfc_copy_shape (mpz_t *, int);
{
/* Clear the shape, since it might not be valid. */
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);
/* Give the expression the right symtree! */
gfc_find_sym_tree (e->symtree->name, NULL, 1, &st);
for (i = 0; i < ref->u.ar.dimen; i++)
ref->u.ar.start[i] = ref->u.ar.end[i] = ref->u.ar.stride[i] = NULL;
- result->rank = ref->u.ar.dimen;
break;
}
+ gfc_free_shape (&result->shape, result->rank);
+
+ /* Recalculate rank, shape, etc. */
+ gfc_resolve_expr (result);
return result;
}
result = SUCCESS;
over:
- for (i--; i >= 0; i--)
- {
- mpz_clear (shape[i]);
- mpz_clear (shape2[i]);
- }
+ gfc_clear_shape (shape, i);
+ gfc_clear_shape (shape2, i);
return result;
}
gfc_add_block_to_block (&block, &loop.pre);
gfc_add_block_to_block (&block, &loop.post);
- for (n = 0; n < cm->as->rank; n++)
- mpz_clear (lss->shape[n]);
- free (lss->shape);
-
+ gfc_free_shape (&lss->shape, cm->as->rank);
gfc_cleanup_loop (&loop);
return gfc_finish_block (&block);
gfc_add_block_to_block (&block, &loop.pre);
gfc_add_block_to_block (&block, &loop.post);
- for (n = 0; n < cm->as->rank; n++)
- mpz_clear (ss->shape[n]);
- free (ss->shape);
-
+ gfc_free_shape (&ss->shape, cm->as->rank);
gfc_cleanup_loop (&loop);
return gfc_finish_block (&block);
+2011-08-22 Mikael Morin <mikael.morin@gcc.gnu.org>
+
+ PR fortran/50050
+ * gfortran.dg/alloc_comp_initializer_3.f90: New test.
+
2011-08-22 Georg-Johann Lay <avr@gjlay.de>
* gcc.dg/pr49994-2.c: Add dg-require-effective-target scheduling.
--- /dev/null
+! { dg-do compile }
+!
+! PR fortran/50050
+! Out of bound whilst releasing initialization of allocate object
+!
+! Contributed by someone <sigurdkn@gmail.com>
+
+program bug
+ implicit none
+ type foo
+ integer, pointer :: a => null()
+ end type
+ type(foo), dimension(:,:), allocatable :: data
+ allocate(data(1:1,1)) ! This used to lead to an ICE
+end program