+2011-02-23 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/40850
+ * trans.c (gfc_prepend_expr_to_block): New function.
+ * trans.h (gfc_prepend_expr_to_block): Declare.
+ * trans-array.c (gfc_conv_array_parameter): Replace
+ gfc_add_expr_to_block with gfc_prepend_expr_to_block.
+
2011-02-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/45743
&& expr->ts.u.derived->attr.alloc_comp
&& expr->expr_type != EXPR_VARIABLE)
{
- tmp = build_fold_indirect_ref_loc (input_location,
- se->expr);
+ tmp = build_fold_indirect_ref_loc (input_location, se->expr);
tmp = gfc_deallocate_alloc_comp (expr->ts.u.derived, tmp, expr->rank);
- gfc_add_expr_to_block (&se->post, tmp);
+
+ /* The components shall be deallocated before their containing entity. */
+ gfc_prepend_expr_to_block (&se->post, tmp);
}
if (g77 || (fsym && fsym->attr.contiguous
*chain = expr;
}
-/* Add a statement to a block. */
+
+/* Add a statement at the end of a block. */
void
gfc_add_expr_to_block (stmtblock_t * block, tree expr)
}
+/* Add a statement at the beginning of a block. */
+
+void
+gfc_prepend_expr_to_block (stmtblock_t * block, tree expr)
+{
+ gcc_assert (block);
+ add_expr_to_chain (&block->head, expr, true);
+}
+
+
/* Add a block the end of a block. */
void
/* Add an expression to the end of a block. */
void gfc_add_expr_to_block (stmtblock_t *, tree);
+/* Add an expression to the beginning of a block. */
+void gfc_prepend_expr_to_block (stmtblock_t *, tree);
/* Add a block to the end of a block. */
void gfc_add_block_to_block (stmtblock_t *, stmtblock_t *);
/* Add a MODIFY_EXPR to a block. */
+2011-02-23 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/40850
+ * gfortran.dg/nested_allocatables_1.f90: New.
+
2011-02-23 Nathan Froyd <froydnj@codesourcery.com>
PR c++/46868
--- /dev/null
+! { dg-do run }
+!
+! PR fortran/40850
+! The code freeing allocatable components used to be put after the code
+! freeing the containing entity.
+!
+! Original test case by Marco Restelli <mrestelli@gmail.com>
+! Reduced by Daniel Franke <franke.daniel@gmail.com>
+! and Janus Weil <janus@gcc.gnu.org>
+
+
+ type t
+ integer, allocatable :: d(:)
+ end type
+ type(t), allocatable :: a(:)
+
+ ! Big enough to make it fail
+ allocate(a(2 * 1024))
+ call sub( (/ a /) )
+
+contains
+
+ subroutine sub(b)
+ type(t) :: b(:)
+ end subroutine
+
+end
+