[7/7] gdb: remove smash_to_memberptr_type

Message ID 20251217155550.37654-8-simon.marchi@efficios.com
State New
Headers
Series gdbtypes cleanups |

Commit Message

Simon Marchi Dec. 17, 2025, 3:55 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

smash_to_memberptr_type is only used by lookup_memberptr_type, remove it
and inline its code there.

Change-Id: I8bc1b8da38f1124e231451aed183d957ea1c37af
---
 gdb/gdbtypes.c | 45 ++++++++++++---------------------------------
 gdb/gdbtypes.h |  9 +++++----
 2 files changed, 17 insertions(+), 37 deletions(-)
  

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f485dfbc8e14..c64fe2fbae99 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -751,18 +751,21 @@  replace_type (struct type *ntype, struct type *type)
   gdb_assert (ntype->instance_flags () == type->instance_flags ());
 }
 
-/* Implement direct support for MEMBER_TYPE in GNU C++.
-   May need to construct such a type if this is the first use.
-   The TYPE is the type of the member.  The DOMAIN is the type
-   of the aggregate that the member belongs to.  */
+/* See gdbtypes.h.  */
 
-struct type *
-lookup_memberptr_type (struct type *type, struct type *domain)
+type *
+lookup_memberptr_type (type *to_type, type *domain)
 {
-  struct type *mtype;
+  type *mtype = type_allocator (to_type).new_type ();
+
+  mtype->set_code (TYPE_CODE_MEMBERPTR);
+  mtype->set_target_type (to_type);
+  set_type_self_type (mtype, domain);
+
+  /* Assume that a data member pointer is the same size as a normal
+     pointer.  */
+  mtype->set_length (gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT);
 
-  mtype = type_allocator (type).new_type ();
-  smash_to_memberptr_type (mtype, domain, type);
   return mtype;
 }
 
@@ -1443,30 +1446,6 @@  set_type_self_type (struct type *type, struct type *self_type)
     }
 }
 
-/* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
-   TO_TYPE.  A member pointer is a weird thing -- it amounts to a
-   typed offset into a struct, e.g. "an int at offset 8".  A MEMBER
-   TYPE doesn't include the offset (that's the value of the MEMBER
-   itself), but does include the structure type into which it points
-   (for some reason).
-
-   When "smashing" the type, we preserve the objfile that the old type
-   pointed to, since we aren't changing where the type is actually
-   allocated.  */
-
-void
-smash_to_memberptr_type (struct type *type, struct type *self_type,
-			 struct type *to_type)
-{
-  smash_type (type);
-  type->set_code (TYPE_CODE_MEMBERPTR);
-  type->set_target_type (to_type);
-  set_type_self_type (type, self_type);
-  /* Assume that a data member pointer is the same size as a normal
-     pointer.  */
-  type->set_length (gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT);
-}
-
 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
 
    When "smashing" the type, we preserve the objfile that the old type
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 2ad8d1044336..f5e7de4d4664 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2462,7 +2462,11 @@  extern const char *address_space_type_instance_flags_to_name
 extern struct type *make_type_with_address_space
   (struct type *type, type_instance_flags space_identifier);
 
-extern struct type *lookup_memberptr_type (struct type *, struct type *);
+/* Implement direct support for MEMBER_TYPE in GNU C++.
+   TO_TYPE is the type of the member.  DOMAIN is the type of the aggregate that
+   the member belongs to.  */
+
+extern type *lookup_memberptr_type (type *to_type, type *domain);
 
 extern struct type *lookup_methodptr_type (struct type *);
 
@@ -2471,9 +2475,6 @@  extern void smash_to_method_type (struct type *type, struct type *self_type,
 				  gdb::array_view<struct field> args,
 				  int varargs);
 
-extern void smash_to_memberptr_type (struct type *, struct type *,
-				     struct type *);
-
 extern void smash_to_methodptr_type (struct type *, struct type *);
 
 extern const char *type_name_or_error (struct type *type);