]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove make_function_type typeptr parameter
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 17 Dec 2025 15:54:58 +0000 (10:54 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 6 Jan 2026 19:59:15 +0000 (14:59 -0500)
In a few places, it is passed nullptr, meaning that we allocate a type
using a type allocator derived from the return type.

In the

  -> lookup_function_type_with_arguments
    -> create_function_type
      -> make_function_type

and

  -> lookup_function_type
    -> create_function_type
      -> make_function_type

paths, we create an allocator based on the return type, pass it down,
and create a type using that, which then gets passed to
make_function_type.  Instead, we can let make_function_type allocate the
type based on the return type.

Change-Id: I3f38e2f4744ab664bd91b006b00501332df617b5
Approved-By: Tom Tromey <tom@tromey.com>
gdb/avr-tdep.c
gdb/ft32-tdep.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/z80-tdep.c

index 237a59e2b244a6e5c552d60f9a6814c4830b0c11..1263dafbf51b0d9306240edca7747b6b26296ca0 100644 (file)
@@ -1475,7 +1475,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
      be defined.  */
   type_allocator alloc (gdbarch);
   tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
-  tdep->func_void_type = make_function_type (tdep->void_type, NULL);
+  tdep->func_void_type = make_function_type (tdep->void_type);
   tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
                                     tdep->func_void_type);
 
index 876ed4ce2fca6ee2e47a5f9190736dbc3260efe8..64bd79a660ad261cdf38487e8781034a0d79c679 100644 (file)
@@ -576,7 +576,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
      be defined.  */
   type_allocator alloc (gdbarch);
   void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
-  func_void_type = make_function_type (void_type, NULL);
+  func_void_type = make_function_type (void_type);
   tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
                                     func_void_type);
   tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags ()
index 087f3393dfdc051e3c559e3f2fcf61b9a85b65a7..30efaa1e9045ec920dbe42770fb5b32ed10559ea 100644 (file)
@@ -476,30 +476,14 @@ lookup_rvalue_reference_type (struct type *type)
   return lookup_reference_type (type, TYPE_CODE_RVALUE_REF);
 }
 
-/* Lookup a function type that returns type TYPE.  TYPEPTR, if
-   nonzero, points to a pointer to memory where the function type
-   should be stored.  If *TYPEPTR is zero, update it to point to the
-   function type we return.  We allocate new memory if needed.  */
+/* See gdbtypes.h.  */
 
-struct type *
-make_function_type (struct type *type, struct type **typeptr)
+type *
+make_function_type (type *return_type)
 {
-  struct type *ntype;  /* New type */
-
-  if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
-    {
-      ntype = type_allocator (type).new_type ();
-      if (typeptr)
-       *typeptr = ntype;
-    }
-  else                 /* We have storage, but need to reset it.  */
-    {
-      ntype = *typeptr;
-      smash_type (ntype);
-    }
-
-  ntype->set_target_type (type);
+  type *ntype = type_allocator (return_type).new_type ();
 
+  ntype->set_target_type (return_type);
   ntype->set_length (1);
   ntype->set_code (TYPE_CODE_FUNC);
 
@@ -512,16 +496,10 @@ make_function_type (struct type *type, struct type **typeptr)
    If the final type in PARAM_TYPES is NULL, create a varargs function.
    New type is allocated using ALLOC.  */
 
-static struct type *
-create_function_type (type_allocator &alloc,
-                    struct type *return_type,
-                    int nparams,
-                    struct type **param_types)
+static type *
+create_function_type (type *return_type, int nparams, type **param_types)
 {
-  struct type *fn = alloc.new_type ();
-  int i;
-
-  make_function_type (return_type, &fn);
+  type *fn = make_function_type (return_type);
 
   if (nparams > 0)
     {
@@ -543,7 +521,7 @@ create_function_type (type_allocator &alloc,
     }
 
   fn->alloc_fields (nparams);
-  for (i = 0; i < nparams; ++i)
+  for (int i = 0; i < nparams; ++i)
     fn->field (i).set_type (param_types[i]);
 
   return fn;
@@ -554,8 +532,7 @@ create_function_type (type_allocator &alloc,
 struct type *
 lookup_function_type (struct type *return_type)
 {
-  type_allocator alloc (return_type);
-  return create_function_type (alloc, return_type, 0, nullptr);
+  return create_function_type (return_type, 0, nullptr);
 }
 
 /* See gdbtypes.h.  */
@@ -565,8 +542,7 @@ lookup_function_type_with_arguments (struct type *return_type,
                                     int nparams,
                                     struct type **param_types)
 {
-  type_allocator alloc (return_type);
-  return create_function_type (alloc, return_type, nparams, param_types);
+  return create_function_type (return_type, nparams, param_types);
 }
 
 /* Identify address space identifier by name -- return a
index 1defdf80ddf4c3a92417e6fc2f8c9cc8bde004ea..11793dd59d29ac3ccb740c744d6efdc73e9d5c9c 100644 (file)
@@ -2518,7 +2518,9 @@ extern type *make_pointer_type (type *type);
 
 extern struct type *lookup_pointer_type (struct type *);
 
-extern struct type *make_function_type (struct type *, struct type **);
+/* Lookup a function type that returns type RETURN_TYPE.  */
+
+extern struct type *make_function_type (type *return_type);
 
 /* Create a new function type with return type RETURN_TYPE and unspecified
    number and types of parameters.
index 4f6ddba547e7cdb1c5994f17256035c2091d6975..e6f29276536854601e2d416b628f76696648f19d 100644 (file)
@@ -1142,7 +1142,7 @@ z80_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   type_allocator alloc (gdbarch);
   tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT,
                                    "void");
-  tdep->func_void_type = make_function_type (tdep->void_type, NULL);
+  tdep->func_void_type = make_function_type (tdep->void_type);
   tdep->pc_type = init_pointer_type (alloc,
                                     tdep->addr_length * TARGET_CHAR_BIT,
                                     NULL, tdep->func_void_type);