[1/2] gdb: simplify code in check_typedef

Message ID 20260727092001.1683349-1-tankutbaris.aktemur@amd.com
State New
Headers
Series [1/2] gdb: simplify code in check_typedef |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Aktemur, Baris July 27, 2026, 9:20 a.m. UTC
  Simplify a code portion in check_typedef where the conditions are
unnecessary.  Also remove the comment that says "treat address spaces
and address classes separately", because since the commit 92fdad7
"gdb: convert type instance flags to bitfields", they are separate
fields; so, the comment does not look useful.
---
 gdb/gdbtypes.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
  

Comments

Keith Seitz July 29, 2026, 5:27 p.m. UTC | #1
Hi,

On 7/27/26 2:20 AM, Tankut Baris Aktemur wrote:
> Simplify a code portion in check_typedef where the conditions are
> unnecessary.  Also remove the comment that says "treat address spaces
> and address classes separately", because since the commit 92fdad7
> "gdb: convert type instance flags to bitfields", they are separate
> fields; so, the comment does not look useful.

Thank you for the quick turnaround for such a, well, minor
corner case. It is very appreciated.

One concern I still have (maybe this is no longer an issue?):
the old logic (and the remaining comment in check_typedef) is outer-wins
on conflict, otherwise inherit from the inner typedef.

Always clearing the RHS and having `merge` never take aspace/class from
it fixes the outer-qualified case, but drops an aspace that appears only
on an inner typedef.

How about encoding outer-wins in `merge` instead, and dropping the 
clearing in check_typedef? That would preserve the previous behavior
(and match the comment).

For example:

type_instance_flags::merge:

    if (harvard_aspace == HARVARD_ASPACE_NONE)
      harvard_aspace = other.harvard_aspace;
    if (address_class == 0)
      address_class = other.address_class;

and check_typedef:

    instance_flags.merge (type->instance_flags ());

I completely agree with the naming change to `merge'. That is
certainly clearer for me.

Thanks,
Keith
  
Aktemur, Baris July 30, 2026, 5:47 a.m. UTC | #2
AMD General

Hello Keith,

On Wednesday, July 29, 2026 7:27 PM, Keith Seitz wrote:
> Hi,
>
> On 7/27/26 2:20 AM, Tankut Baris Aktemur wrote:
> > Simplify a code portion in check_typedef where the conditions are
> > unnecessary.  Also remove the comment that says "treat address spaces
> > and address classes separately", because since the commit 92fdad7
> > "gdb: convert type instance flags to bitfields", they are separate
> > fields; so, the comment does not look useful.
>
> Thank you for the quick turnaround for such a, well, minor
> corner case. It is very appreciated.
>
> One concern I still have (maybe this is no longer an issue?):
> the old logic (and the remaining comment in check_typedef) is outer-wins
> on conflict, otherwise inherit from the inner typedef.
>
> Always clearing the RHS and having `merge` never take aspace/class from
> it fixes the outer-qualified case, but drops an aspace that appears only
> on an inner typedef.

This is absolutely right.  I didn't intend to change the existing behavior.
I think I simply didn't see the code correctly (I will increase my editor's
font size).

> How about encoding outer-wins in `merge` instead, and dropping the
> clearing in check_typedef? That would preserve the previous behavior
> (and match the comment).
>
> For example:
>
> type_instance_flags::merge:
>
>     if (harvard_aspace == HARVARD_ASPACE_NONE)
>       harvard_aspace = other.harvard_aspace;
>     if (address_class == 0)
>       address_class = other.address_class;
>
> and check_typedef:
>
>     instance_flags.merge (type->instance_flags ());
>
> I completely agree with the naming change to `merge'. That is
> certainly clearer for me.
>
> Thanks,
> Keith

I'll send the update with these changes.

Thank you for taking the time to review.

-Baris
  

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 9098727959e..ad401872941 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3062,12 +3062,8 @@  check_typedef (struct type *type)
 	 "it can't happen".  */
       {
 	type_instance_flags new_instance_flags = type->instance_flags ();
-
-	/* Treat code vs data spaces and address classes separately.  */
-	if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE)
-	  new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE;
-	if (instance_flags.address_class != 0)
-	  new_instance_flags.address_class = 0;
+	new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE;
+	new_instance_flags.address_class = 0;
 
 	instance_flags |= new_instance_flags;
       }