https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101919
--- Comment #4 from anlauf at gcc dot gnu.org --- This fixes comment#2: diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index e7aec3845d3..f7e2a0dba57 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -8102,10 +8102,12 @@ gfc_trans_string_copy (stmtblock_t * block, tree dlength, tree dest, tmp3 = gfc_finish_block (&tempblock); /* The truncated memmove if the slen >= dlen. */ + tmp2 = fold_build2_loc (input_location, MIN_EXPR, + TREE_TYPE (slen), slen, dlen); tmp2 = build_call_expr_loc (input_location, builtin_decl_explicit (BUILT_IN_MEMMOVE), 3, dest, src, - fold_convert (size_type_node, dlen)); + fold_convert (size_type_node, tmp2)); /* The whole copy_string function is there. */ tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond2,