* [PATCH 1/2] gdb: remove dead code in make_pointer_type and make_reference_type
@ 2026-08-03 14:35 Tankut Baris Aktemur
2026-08-03 14:35 ` [PATCH 2/2] gdb: do minor code modernization " Tankut Baris Aktemur
2026-08-03 14:50 ` [PATCH 1/2] gdb: remove dead code " Simon Marchi
0 siblings, 2 replies; 4+ messages in thread
From: Tankut Baris Aktemur @ 2026-08-03 14:35 UTC (permalink / raw)
To: gdb-patches
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.
---
gdb/gdbtypes.c | 21 ---------------------
1 file changed, 21 deletions(-)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 9098727959e..2dda175237c 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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;
}
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] gdb: do minor code modernization in make_pointer_type and make_reference_type
2026-08-03 14:35 [PATCH 1/2] gdb: remove dead code in make_pointer_type and make_reference_type Tankut Baris Aktemur
@ 2026-08-03 14:35 ` Tankut Baris Aktemur
2026-08-03 14:51 ` Simon Marchi
2026-08-03 14:50 ` [PATCH 1/2] gdb: remove dead code " Simon Marchi
1 sibling, 1 reply; 4+ messages in thread
From: Tankut Baris Aktemur @ 2026-08-03 14:35 UTC (permalink / raw)
To: gdb-patches
This is a small code modernization. There should be no behavioral
change.
---
gdb/gdbtypes.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 2dda175237c..409601abe03 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -366,10 +366,8 @@ smash_type (struct type *type)
type *
make_pointer_type (type *type)
{
- struct type *ntype; /* New type */
- ntype = type->pointer_type;
-
- if (ntype)
+ struct type *ntype = type->pointer_type;
+ if (ntype != nullptr)
return ntype;
ntype = type_allocator (type).new_type ();
@@ -403,23 +401,22 @@ lookup_pointer_type (struct type *type)
type *
make_reference_type (type *type, type_code refcode)
{
- struct type *ntype; /* New type */
- struct type **reftype;
-
gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
- ntype = (refcode == TYPE_CODE_REF ? type->reference_type
- : type->rvalue_reference_type);
+ struct type *ntype = (refcode == TYPE_CODE_REF
+ ? type->reference_type
+ : type->rvalue_reference_type);
- if (ntype)
+ if (ntype != nullptr)
return ntype;
ntype = type_allocator (type).new_type ();
ntype->set_target_type (type);
- reftype = (refcode == TYPE_CODE_REF ? &type->reference_type
- : &type->rvalue_reference_type);
- *reftype = ntype;
+ if (refcode == TYPE_CODE_REF)
+ type->reference_type = ntype;
+ else
+ type->rvalue_reference_type = ntype;
/* FIXME! Assume the machine has only one representation for
references, and that it matches the (only) representation for
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] gdb: remove dead code in make_pointer_type and make_reference_type
2026-08-03 14:35 [PATCH 1/2] gdb: remove dead code in make_pointer_type and make_reference_type Tankut Baris Aktemur
2026-08-03 14:35 ` [PATCH 2/2] gdb: do minor code modernization " Tankut Baris Aktemur
@ 2026-08-03 14:50 ` Simon Marchi
1 sibling, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2026-08-03 14:50 UTC (permalink / raw)
To: Tankut Baris Aktemur, gdb-patches
On 8/3/26 10:35 AM, Tankut Baris Aktemur wrote:
> 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.
Thanks, this LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] gdb: do minor code modernization in make_pointer_type and make_reference_type
2026-08-03 14:35 ` [PATCH 2/2] gdb: do minor code modernization " Tankut Baris Aktemur
@ 2026-08-03 14:51 ` Simon Marchi
0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2026-08-03 14:51 UTC (permalink / raw)
To: Tankut Baris Aktemur, gdb-patches
On 8/3/26 10:35 AM, Tankut Baris Aktemur wrote:
> This is a small code modernization. There should be no behavioral
> change.
Thanks, this LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-03 14:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03 14:35 [PATCH 1/2] gdb: remove dead code in make_pointer_type and make_reference_type Tankut Baris Aktemur
2026-08-03 14:35 ` [PATCH 2/2] gdb: do minor code modernization " Tankut Baris Aktemur
2026-08-03 14:51 ` Simon Marchi
2026-08-03 14:50 ` [PATCH 1/2] gdb: remove dead code " Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox