+2006-06-08 Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+ PR fortran/27958
+ * trans-expr.c (gfc_conv_substring): If the substring start is
+ greater than its end, the length of the substring is zero, and
+ not negative.
+ (gfc_trans_string_copy): Don't generate a call to
+ _gfortran_copy_string when destination length is zero.
+
2006-06-08 Asher Langton <langton2@llnl.gov>
PR fortran/27786
build_int_cst (gfc_charlen_type_node, 1),
start.expr);
tmp = fold_build2 (PLUS_EXPR, gfc_charlen_type_node, end.expr, tmp);
+ tmp = fold_build2 (MAX_EXPR, gfc_charlen_type_node, tmp,
+ build_int_cst (gfc_charlen_type_node, 0));
se->string_length = tmp;
}
tree tmp;
tree dsc;
tree ssc;
+ tree cond;
/* Deal with single character specially. */
dsc = gfc_to_single_character (dlen, dest);
return;
}
+ cond = fold_build2 (GT_EXPR, boolean_type_node, dlen,
+ build_int_cst (gfc_charlen_type_node, 0));
+
tmp = NULL_TREE;
tmp = gfc_chainon_list (tmp, dlen);
tmp = gfc_chainon_list (tmp, dest);
tmp = gfc_chainon_list (tmp, slen);
tmp = gfc_chainon_list (tmp, src);
tmp = build_function_call_expr (gfor_fndecl_copy_string, tmp);
+ tmp = fold_build3 (COND_EXPR, void_type_node, cond, tmp, build_empty_stmt ());
gfc_add_expr_to_block (block, tmp);
}
--- /dev/null
+! { dg-do run }
+! Check that substrings behave correctly even when zero-sized
+ implicit none
+ character(len=10) :: s, t
+ integer :: i, j
+
+ s = "abcdefghij"
+ t(:10) = s(1:)
+ s(6:5) = "foo"
+ if (s /= t) call abort
+ i = 2
+ j = -1
+ s(i:i+j) = "foo"
+ if (s /= t) call abort
+ i = 20
+ s(i+1:i) = "foo"
+ if (s /= t) call abort
+ s(6:5) = s(7:5)
+ if (s /= t) call abort
+ s = t(7:6)
+ if (len(trim(s)) /= 0) call abort
+ if (len(t(8:4)) /= 0) call abort
+ if (len(trim(t(8:4))) /= 0) call abort
+ end