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

--- Comment #7 from anlauf at gcc dot gnu.org ---
Untested patch:

diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index a2376917635..7699e98f6ea 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -689,9 +689,14 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree
size)
   /* Call malloc.  */
   gfc_start_block (&block2);

-  size = fold_convert (size_type_node, size);
-  size = fold_build2_loc (input_location, MAX_EXPR, size_type_node, size,
-                         build_int_cst (size_type_node, 1));
+  if (size)
+    {
+      size = fold_convert (size_type_node, size);
+      size = fold_build2_loc (input_location, MAX_EXPR, size_type_node, size,
+                             build_int_cst (size_type_node, 1));
+    }
+  else
+    size = build_int_cst (size_type_node, 1);

   malloc_tree = builtin_decl_explicit (BUILT_IN_MALLOC);
   gfc_add_modify (&block2, res,

Not sure if this is correct, but it makes gfc_call_malloc match the comment
preceeding that function.

I'll leave the interpretation to the experts.

Reply via email to