public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Increase size of main_type::nfields
Date: Wed, 11 Jan 2023 16:02:55 -0500	[thread overview]
Message-ID: <061d47f1-fbe7-4d2f-6919-811061d0be9b@simark.ca> (raw)
In-Reply-To: <20230111204418.376620-1-tromey@adacore.com>



On 1/11/23 15:44, Tom Tromey via Gdb-patches wrote:
> main_type::nfields is a 'short', and has been for many years.  PR
> c++/29985 points out that 'short' is too narrow for an enum that
> contains more than 2^15 constants.
> 
> This patch bumps the size of 'nfields'.  To verify that the field
> isn't directly used, it is also renamed.  Note that this does not
> affect the size of main_type on x86-64 Fedora 36.  And, if it does
> have a negative effect somewhere, it's worth considering that types
> could be shrunk more drastically by using subclasses for the different
> codes.
> 
> I wasn't sure whether a test case for this would be desirable.  It
> would be a bit large.

We could make a test case that generates a source file on the fly in
standard_output_directory and compiles it.

> ---
>  gdb/gdb-gdb.py.in | 4 ++--
>  gdb/gdbtypes.h    | 6 +++---
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
> index dbc4d773e0b..95b7d84966f 100644
> --- a/gdb/gdb-gdb.py.in
> +++ b/gdb/gdb-gdb.py.in
> @@ -261,8 +261,8 @@ class StructMainTypePrettyPrinter:
>          fields.append("flags = [%s]" % self.flags_to_string())
>          fields.append("owner = %s" % self.owner_to_string())
>          fields.append("target_type = %s" % self.val["m_target_type"])
> -        if self.val["nfields"] > 0:
> -            for fieldno in range(self.val["nfields"]):
> +        if self.val["m_nfields"] > 0:
> +            for fieldno in range(self.val["m_nfields"]):
>                  fields.append(self.struct_field_img(fieldno))
>          if self.val["code"] == gdb.TYPE_CODE_RANGE:
>              fields.append(self.bounds_img())
> diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
> index a9abb0d8071..da1d0f79d1f 100644
> --- a/gdb/gdbtypes.h
> +++ b/gdb/gdbtypes.h
> @@ -836,7 +836,7 @@ struct main_type
>    /* * Number of fields described for this type.  This field appears
>       at this location because it packs nicely here.  */
>  
> -  short nfields;
> +  int m_nfields;

Should it be unsigned?  I don't recall this field needing to be
negative.

Otherwise, LGTM.

Simon

  reply	other threads:[~2023-01-11 21:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 20:44 Tom Tromey
2023-01-11 21:02 ` Simon Marchi [this message]
2023-01-11 21:28   ` Tom Tromey
2023-01-11 22:33     ` Simon Marchi
2023-01-12 19:14       ` Tom Tromey
2023-01-13 12:53   ` Pedro Alves
2023-01-27 14:49     ` Tom Tromey
2023-01-27 15:13   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=061d47f1-fbe7-4d2f-6919-811061d0be9b@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).