https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68401

--- Comment #6 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 
---
(In reply to Mikael Morin from comment #5)
> (In reply to Joost VandeVondele from comment #4)
> > In the original post I suggested that I already looked at the code,
> 
> What changes did you try?

Baby steps :-) see below. Basically stuck when I realized that somehow the
'tree size' needs to get in.

Index: fortran/trans.c
===================================================================
--- fortran/trans.c     (revision 227094)
+++ fortran/trans.c     (working copy)
@@ -567,6 +567,8 @@ gfc_call_malloc (stmtblock_t * block, tr
   tree tmp, msg, malloc_result, null_result, res, malloc_tree;
   stmtblock_t block2;

+  char* msgstr;
+
   size = gfc_evaluate_now (size, block);

   if (TREE_TYPE (size) != TREE_TYPE (size_type_node))
@@ -593,8 +595,9 @@ gfc_call_malloc (stmtblock_t * block, tr
       null_result = fold_build2_loc (input_location, EQ_EXPR,
                                     boolean_type_node, res,
                                     build_int_cst (pvoid_type_node, 0));
+      msgstr = xasprintf("Memory allocation of %ld bytes failed",0L);
       msg = gfc_build_addr_expr (pchar_type_node,
-             gfc_build_localized_cstring_const ("Memory allocation failed"));
+             gfc_build_localized_cstring_const (msgstr));
       tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node,
                             null_result,
              build_call_expr_loc (input_location,
@@ -641,6 +644,7 @@ gfc_allocate_using_malloc (stmtblock_t *
 {
   tree tmp, error_cond;
   stmtblock_t on_error;
+  char* msgstr;
   tree status_type = status ? TREE_TYPE (status) : NULL_TREE;

   /* Evaluate size only once, and make sure it has the right type.  */
@@ -677,10 +681,12 @@ gfc_allocate_using_malloc (stmtblock_t *
   else
     {
       /* Here, os_error already implies PRED_NORETURN.  */
+      /* TODO figure out how to get 'size' in this string */
+      msgstr=xasprintf("Allocation of %ld bytes would exceed memory
limit",-1L);
       tmp = build_call_expr_loc (input_location, gfor_fndecl_os_error, 1,
-                   gfc_build_addr_expr (pchar_type_node,
-                                gfc_build_localized_cstring_const
-                                   ("Allocation would exceed memory limit")));
+                   gfc_build_addr_expr (pchar_type_node,
gfc_build_cstring_const(msgstr)));
+               /*               gfc_build_localized_cstring_const
+                                   ("Allocation would exceed memory limit")));
*/
       gfc_add_expr_to_block (&on_error, tmp);
     }

Reply via email to