]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove dead code in make_pointer_type and make_reference_type
authorTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Mon, 3 Aug 2026 13:38:34 +0000 (15:38 +0200)
committerTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Mon, 3 Aug 2026 15:30:53 +0000 (17:30 +0200)
At the end of `make_pointer_type` and `make_reference_type`, GDB
updates the length of every type in the chain.  This is practically
dead code, because if we reach this point, we must have allocated a
new type.  After a new allocation, the chain contains only the
newly-created type itself.  See in `type_allocator::new_type ()`:

  type->chain = type;   /* Chain back to itself.  */

That is, we always have `ntype == ntype->chain`.  Therefore, the loop
can never be entered.  Remove it.

In `make_reference_type`, we also remove `*reftype = ntype;`, because
a few lines above the assignment was already made.  This is repeated
code.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/gdbtypes.c

index 9098727959ebe1ea4c266e11c4e74e39d48df35d..2dda175237c09ac046b84c6d01d92a065f7eacdd 100644 (file)
@@ -367,8 +367,6 @@ type *
 make_pointer_type (type *type)
 {
   struct type *ntype;  /* New type */
-  struct type *chain;
-
   ntype = type->pointer_type;
 
   if (ntype)
@@ -388,14 +386,6 @@ make_pointer_type (type *type)
      gdbarch_address_to_pointer.  */
   ntype->set_is_unsigned (true);
 
-  /* Update the length of all the other variants of this type.  */
-  chain = ntype->chain;
-  while (chain != ntype)
-    {
-      chain->set_length (ntype->length ());
-      chain = chain->chain;
-    }
-
   return ntype;
 }
 
@@ -415,7 +405,6 @@ make_reference_type (type *type, type_code refcode)
 {
   struct type *ntype;  /* New type */
   struct type **reftype;
-  struct type *chain;
 
   gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
 
@@ -439,16 +428,6 @@ make_reference_type (type *type, type_code refcode)
   ntype->set_length (gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT);
   ntype->set_code (refcode);
 
-  *reftype = ntype;
-
-  /* Update the length of all the other variants of this type.  */
-  chain = ntype->chain;
-  while (chain != ntype)
-    {
-      chain->set_length (ntype->length ());
-      chain = chain->chain;
-    }
-
   return ntype;
 }