diff options
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r-- | gcc/fortran/trans-expr.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 239e41e..34be30c 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -261,6 +261,10 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind, gfc_conv_string_parameter (se); else { + /* Avoid multiple evaluation of substring start. */ + if (!CONSTANT_CLASS_P (start.expr) && !DECL_P (start.expr)) + start.expr = gfc_evaluate_now (start.expr, &se->pre); + /* Change the start of the string. */ if (TYPE_STRING_FLAG (TREE_TYPE (se->expr))) tmp = se->expr; @@ -279,6 +283,9 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind, gfc_conv_expr_type (&end, ref->u.ss.end, gfc_charlen_type_node); gfc_add_block_to_block (&se->pre, &end.pre); } + if (!CONSTANT_CLASS_P (end.expr) && !DECL_P (end.expr)) + end.expr = gfc_evaluate_now (end.expr, &se->pre); + if (flag_bounds_check) { tree nonempty = fold_build2 (LE_EXPR, boolean_type_node, |