[COMMITTED] algol68: use a runtime libcall rather than a builtin for malloc

Jose E. Marchesi jemarch@gnu.org
Fri Mar 14 23:48:44 GMT 2025


---
 gcc/algol68/a68-low-builtins.cc | 8 --------
 gcc/algol68/a68-low-runtime.cc  | 3 +++
 gcc/algol68/a68-low-runtime.def | 1 +
 gcc/algol68/a68-low.cc          | 7 +++----
 4 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/gcc/algol68/a68-low-builtins.cc b/gcc/algol68/a68-low-builtins.cc
index 08111b1d562..eabf7b34835 100644
--- a/gcc/algol68/a68-low-builtins.cc
+++ b/gcc/algol68/a68-low-builtins.cc
@@ -530,12 +530,4 @@ a68_install_builtins (void)
       local_define_builtin ("__builtin_expl", ftype, BUILT_IN_EXPL,
 			    "expl", ECF_NOTHROW | ECF_LEAF);
     }
-
-  /* XXX it is better to define a BUILT_IN_LIBGA68_MALLOC  */
-  if (!builtin_decl_explicit_p (BUILT_IN_MALLOC))
-    {
-      tree ftype = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
-      local_define_builtin ("__malloc", ftype, BUILT_IN_MALLOC,
-			    "_libga68_malloc", ECF_NOTHROW | ECF_LEAF);
-    }
 }
diff --git a/gcc/algol68/a68-low-runtime.cc b/gcc/algol68/a68-low-runtime.cc
index 7b409cb78f2..3e9177dbc9a 100644
--- a/gcc/algol68/a68-low-runtime.cc
+++ b/gcc/algol68/a68-low-runtime.cc
@@ -53,6 +53,7 @@ enum a68_libcall_type
   LCT_VOID,
   LCT_CHAR,
   LCT_CONSTCHARPTR,
+  LCT_VOIDPTR,
   LCT_UNISTR,
   LCT_UNISTRPTR,
   LCT_SIZE,
@@ -88,6 +89,8 @@ get_libcall_type (a68_libcall_type type)
   else if (type == LCT_CONSTCHARPTR)
     libcall_types[type] = build_pointer_type (build_qualified_type (char_type_node,
 								    TYPE_QUAL_CONST));
+  else if (type == LCT_VOIDPTR)
+    libcall_types[type] = ptr_type_node;
   else if (type == LCT_UNISTR)
     libcall_types[type] = build_pointer_type (CTYPE (M_CHAR));
   else if (type == LCT_UNISTRPTR)
diff --git a/gcc/algol68/a68-low-runtime.def b/gcc/algol68/a68-low-runtime.def
index cf023bc98ed..443884425c5 100644
--- a/gcc/algol68/a68-low-runtime.def
+++ b/gcc/algol68/a68-low-runtime.def
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3.  If not see
    Used for declaring functions that are called by generated code.  */
 
 DEF_A68_RUNTIME (ASSERT, "_libga68_assert", RT(VOID), P2(CONSTCHARPTR, UINT), ECF_NORETURN)
+DEF_A68_RUNTIME (MALLOC, "_libga68_malloc", RT(VOIDPTR), P1(SIZE), ECF_NOTHROW | ECF_LEAF)
 DEF_A68_RUNTIME (DEREFNIL, "_libga68_derefnil", RT(VOID), P2(CONSTCHARPTR, UINT), 0)
 DEF_A68_RUNTIME (BITSBOUNDSERROR, "_libga68_bitsboundserror", RT(VOID), P3(CONSTCHARPTR,UINT,INT), 0)
 DEF_A68_RUNTIME (ARRAYBOUNDS, "_libga68_bounds", RT(VOID),
diff --git a/gcc/algol68/a68-low.cc b/gcc/algol68/a68-low.cc
index 6a04d5baeb6..c4d8172543b 100644
--- a/gcc/algol68/a68-low.cc
+++ b/gcc/algol68/a68-low.cc
@@ -868,10 +868,9 @@ a68_lower_alloca (tree type, tree size)
 tree
 a68_lower_malloc (tree type, tree size)
 {
-  tree call = builtin_decl_explicit (BUILT_IN_MALLOC);
-  call = build_call_expr_loc (UNKNOWN_LOCATION, call, 1, size);
-  call = fold_convert (build_pointer_type (type), call);
-  return call;
+  return fold_convert (build_pointer_type (type),
+		       a68_build_libcall (A68_LIBCALL_MALLOC, ptr_type_node,
+					  1, size));
 }
 
 /* Build code for a temporary variable named NAME, of type TYPE and initialized
-- 
2.30.2



More information about the Algol68 mailing list