+2016-08-08 Andre Vehreschild <vehre@gcc.gnu.org>
+
+ PR fortran/72698
+ * trans-stmt.c (gfc_trans_allocate): Prevent generating code for
+ copy of zero sized string and with it an ICE.
+
2016-08-08 Andre Vehreschild <vehre@gcc.gnu.org>
PR fortran/70524
}
gfc_add_block_to_block (&block, &se.pre);
gfc_add_block_to_block (&post, &se.post);
+
+ /* Special case when string in expr3 is zero. */
+ if (code->expr3->ts.type == BT_CHARACTER
+ && integer_zerop (se.string_length))
+ {
+ gfc_init_se (&se, NULL);
+ temp_var_needed = false;
+ expr3_len = integer_zero_node;
+ e3_is = E3_MOLD;
+ }
/* Prevent aliasing, i.e., se.expr may be already a
variable declaration. */
- if (se.expr != NULL_TREE && temp_var_needed)
+ else if (se.expr != NULL_TREE && temp_var_needed)
{
tree var, desc;
tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) || is_coarray ?
gcc_assert (expr3_esize);
expr3_esize = fold_convert (sizetype, expr3_esize);
if (e3_is == E3_MOLD)
- {
- /* The expr3 is no longer valid after this point. */
- expr3 = NULL_TREE;
- e3_is = E3_UNSET;
- }
+ /* The expr3 is no longer valid after this point. */
+ expr3 = NULL_TREE;
}
else if (code->ext.alloc.ts.type != BT_UNKNOWN)
{
fold_convert (TREE_TYPE (al_len),
integer_zero_node));
}
- if (code->expr3 && !code->expr3->mold)
+ if (code->expr3 && !code->expr3->mold && e3_is != E3_MOLD)
{
/* Initialization via SOURCE block (or static default initializer).
Classes need some special handling, so catch them first. */
--- /dev/null
+! { dg-do run }
+
+! Check that PR72698 is fixed.
+! Contributed by Gerhard Steinmetz
+
+module m
+contains
+ integer function f()
+ f = 4
+ end
+end
+program p
+ use m
+ character(3), parameter :: c = 'abc'
+ character(:), allocatable :: z
+ allocate (z, source=repeat(c(2:1), f()))
+ if (len(z) /= 0) call abort()
+ if (z /= "") call abort()
+end
+
+