[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug fortran/58579] Memory allocation fails when calling character-valued function
From:       "burnus at gcc dot gnu.org" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2013-09-30 21:20:12
Message-ID: bug-58579-4-JadPZaUXAG () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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.  */
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic