From: Tobias Burnus Date: Sun, 27 Feb 2011 14:12:31 +0000 (+0100) Subject: re PR fortran/47846 (Deferred-string length: Length is wrong (gfortran.dg/allocate_de... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2573aab954b1dc8da8d690b4425856c870bba01e;p=gcc.git re PR fortran/47846 (Deferred-string length: Length is wrong (gfortran.dg/allocate_deferred_char_scalar_1.f03)) 2011-02-27 Tobias Burnus PR fortran/47846 * trans-stmt.c (gfc_trans_allocate): Fix allocation with type-spec of deferred-length strings. From-SVN: r170539 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c6836f7e674..d79d45e0759 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-02-26 Tobias Burnus + + PR fortran/47846 + * trans-stmt.c (gfc_trans_allocate): Fix allocation with + type-spec of deferred-length strings. + 2011-02-26 Tobias Burnus PR fortran/47886 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index e1202858bb2..98fb74c4578 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -4581,6 +4581,25 @@ gfc_trans_allocate (gfc_code * code) TREE_TYPE (tmp), tmp, fold_convert (TREE_TYPE (tmp), memsz)); } + else if (al->expr->ts.type == BT_CHARACTER && al->expr->ts.deferred) + { + gcc_assert (code->ext.alloc.ts.u.cl && code->ext.alloc.ts.u.cl->length); + gfc_init_se (&se_sz, NULL); + gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length); + gfc_add_block_to_block (&se.pre, &se_sz.pre); + se_sz.expr = gfc_evaluate_now (se_sz.expr, &se.pre); + gfc_add_block_to_block (&se.pre, &se_sz.post); + /* Store the string length. */ + tmp = al->expr->ts.u.cl->backend_decl; + gfc_add_modify (&se.pre, tmp, fold_convert (TREE_TYPE (tmp), + se_sz.expr)); + tmp = TREE_TYPE (gfc_typenode_for_spec (&code->ext.alloc.ts)); + tmp = TYPE_SIZE_UNIT (tmp); + memsz = fold_build2_loc (input_location, MULT_EXPR, + TREE_TYPE (tmp), tmp, + fold_convert (TREE_TYPE (se_sz.expr), + se_sz.expr)); + } else if (code->ext.alloc.ts.type != BT_UNKNOWN) memsz = TYPE_SIZE_UNIT (gfc_typenode_for_spec (&code->ext.alloc.ts)); else