public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Do not change type in get_discrete_low_bound
Date: Thu, 27 Apr 2023 13:35:15 -0600	[thread overview]
Message-ID: <20230427193515.1060101-1-tromey@adacore.com> (raw)

get_discrete_low_bound has this code:

    /* Set unsigned indicator if warranted.  */
    if (low >= 0)
      type->set_is_unsigned (true);

It's bad to modify a type in a getter like this, so this patch removes
this code.  FWIW I looked and this code has been there since at least
1999 (it was in the initial sourceware import).

Types in general would benefit from const-ification, which would
probably reveal more code like this, but I haven't attempted that.

Regression tested on x86-64 Fedora 36.
---
 gdb/gdbtypes.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6af59351b76..c8d5314bce7 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1084,10 +1084,6 @@ get_discrete_low_bound (struct type *type)
 		  low = type->field (i).loc_enumval ();
 	      }
 
-	    /* Set unsigned indicator if warranted.  */
-	    if (low >= 0)
-	      type->set_is_unsigned (true);
-
 	    return low;
 	  }
 	else
-- 
2.39.1


             reply	other threads:[~2023-04-27 19:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 19:35 Tom Tromey [this message]
2023-04-28 16:07 ` Kevin Buettner

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=20230427193515.1060101-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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).