From: Simon Marchi Date: Wed, 17 Dec 2025 15:54:58 +0000 (-0500) Subject: gdb: remove make_function_type typeptr parameter X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3c7c6ad37a2a2e66ebe61939ed17ac574243c55;p=thirdparty%2Fbinutils-gdb.git gdb: remove make_function_type typeptr parameter 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 --- diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c index 237a59e2b24..1263dafbf51 100644 --- a/gdb/avr-tdep.c +++ b/gdb/avr-tdep.c @@ -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); diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c index 876ed4ce2fc..64bd79a660a 100644 --- a/gdb/ft32-tdep.c +++ b/gdb/ft32-tdep.c @@ -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 () diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 087f3393dfd..30efaa1e904 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -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 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 1defdf80ddf..11793dd59d2 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -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. diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c index 4f6ddba547e..e6f29276536 100644 --- a/gdb/z80-tdep.c +++ b/gdb/z80-tdep.c @@ -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);