http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Completely untested draft patch
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2355,11 +2355,13 @@ gfc_conv_string_tmp (gfc_se * se, tree type, tree len)
{
/* Allocate a temporary to hold the result. */
var = gfc_create_var (type, "pstr");
+ tmp = TYPE_SIZE_UNIT (get_element_type (type));
+ tmp = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+ fold_convert (size_type_node, len),
+ fold_convert (size_type_node, tmp));
tmp = gfc_call_malloc (&se->pre, type,
fold_build2_loc (input_location, MULT_EXPR,
- TREE_TYPE (len), len,
- fold_convert (TREE_TYPE (len),
- TYPE_SIZE
(type))));
+ size_type_node, len, tmp);
gfc_add_modify (&se->pre, var, tmp);
/* Free the temporary afterwards. */