aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2018-09-21 17:33:29 +0000
committerPaul Thomas <pault@gcc.gnu.org>2018-09-21 17:33:29 +0000
commit5b4dd0158308d1a3effffd6316f1b39fdd1ad120 (patch)
tree724835af8e907b547caed382d219d76051a50c9c /gcc/fortran
parentfd876246ee8a5aabb710673f7a8bc49b7c15fe84 (diff)
downloadgcc-5b4dd0158308d1a3effffd6316f1b39fdd1ad120.zip
gcc-5b4dd0158308d1a3effffd6316f1b39fdd1ad120.tar.gz
gcc-5b4dd0158308d1a3effffd6316f1b39fdd1ad120.tar.bz2
re PR fortran/77325 (ICE in gimplify_var_or_parm_decl, at gimplify.c:1933)
2018-09-21 Paul Thomas <pault@gcc.gnu.org> PR fortran/77325 * trans-array.c (gfc_alloc_allocatable_for_assignment): If the rhs has a charlen expression, convert that and use it. * trans-expr.c (gfc_trans_assignment_1): The rse.pre for the assignment of deferred character array vars to a realocatable lhs should not be added to the exterior block since vector indices, for example, generate temporaries indexed within the loop. 2018-09-21 Paul Thomas <pault@gcc.gnu.org> PR fortran/77325 * gfortran.dg/deferred_character_22.f90 : New test. From-SVN: r264486
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/ChangeLog11
-rw-r--r--gcc/fortran/trans-array.c9
-rw-r--r--gcc/fortran/trans-expr.c14
3 files changed, 29 insertions, 5 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 0d8797e..e6bf429 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,16 @@
2018-09-21 Paul Thomas <pault@gcc.gnu.org>
+ PR fortran/77325
+ * trans-array.c (gfc_alloc_allocatable_for_assignment): If the
+ rhs has a charlen expression, convert that and use it.
+ * trans-expr.c (gfc_trans_assignment_1): The rse.pre for the
+ assignment of deferred character array vars to a realocatable
+ lhs should not be added to the exterior block since vector
+ indices, for example, generate temporaries indexed within the
+ loop.
+
+2018-09-21 Paul Thomas <pault@gcc.gnu.org>
+
PR fortran/87359
* trans-stmt.c (gfc_trans_allocate): Don't deallocate alloc
components if must_finalize is set for expr3.
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 95ea615..9e00eb0 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -9964,6 +9964,15 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop,
tmp = concat_str_length (expr2);
expr2->ts.u.cl->backend_decl = gfc_evaluate_now (tmp, &fblock);
}
+ else if (!tmp && expr2->ts.u.cl->length)
+ {
+ gfc_se tmpse;
+ gfc_init_se (&tmpse, NULL);
+ gfc_conv_expr_type (&tmpse, expr2->ts.u.cl->length,
+ gfc_charlen_type_node);
+ tmp = tmpse.expr;
+ expr2->ts.u.cl->backend_decl = gfc_evaluate_now (tmp, &fblock);
+ }
tmp = fold_convert (TREE_TYPE (expr1->ts.u.cl->backend_decl), tmp);
}
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 1f94dcf..1453828 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -10275,17 +10275,21 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
/* When assigning a character function result to a deferred-length variable,
the function call must happen before the (re)allocation of the lhs -
otherwise the character length of the result is not known.
- NOTE: This relies on having the exact dependence of the length type
+ NOTE 1: This relies on having the exact dependence of the length type
parameter available to the caller; gfortran saves it in the .mod files.
- NOTE ALSO: The concatenation operation generates a temporary pointer,
+ NOTE 2: Vector array references generate an index temporary that must
+ not go outside the loop. Otherwise, variables should not generate
+ a pre block.
+ NOTE 3: The concatenation operation generates a temporary pointer,
whose allocation must go to the innermost loop.
- NOTE ALSO (2): Elemental functions may generate a temporary, too. */
+ NOTE 4: Elemental functions may generate a temporary, too. */
if (flag_realloc_lhs
&& expr2->ts.type == BT_CHARACTER && expr1->ts.deferred
&& !(lss != gfc_ss_terminator
&& rss != gfc_ss_terminator
- && ((expr2->expr_type == EXPR_FUNCTION
- && expr2->value.function.esym != NULL
+ && ((expr2->expr_type == EXPR_VARIABLE && expr2->rank)
+ || (expr2->expr_type == EXPR_FUNCTION
+ && expr2->value.function.esym != NULL
&& expr2->value.function.esym->attr.elemental)
|| (expr2->expr_type == EXPR_FUNCTION
&& expr2->value.function.isym != NULL