public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: some int to unsigned int conversion
@ 2023-01-21 14:56 Enze Li
  2023-01-21 17:09 ` Tom Tromey
  2023-01-22  5:54 ` [PATCH v2] gdb: some int to bool conversion Enze Li
  0 siblings, 2 replies; 6+ messages in thread
From: Enze Li @ 2023-01-21 14:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: enze.li

When building GDB with clang 16, I got this,

  CXX    maint.o
maint.c:1045:23: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_space_enabled = 1;
                      ^ ~
maint.c:1057:22: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_time_enabled = 1;
                     ^ ~
maint.c:1073:24: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_symtab_enabled = 1;
                       ^ ~
3 errors generated.

Work around this by using unsigned int instead.

Tested by rebuilding on x86_64-linux with clang 16 and gcc 12.
---
 gdb/maint.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/maint.h b/gdb/maint.h
index 09a68c17befd..71f63b2e39be 100644
--- a/gdb/maint.h
+++ b/gdb/maint.h
@@ -49,9 +49,9 @@ class scoped_command_stats
   /* Track whether the stat was enabled at the start of the command
      so that we can avoid printing anything if it gets turned on by
      the current command.  */
-  int m_time_enabled : 1;
-  int m_space_enabled : 1;
-  int m_symtab_enabled : 1;
+  unsigned int m_time_enabled : 1;
+  unsigned int m_space_enabled : 1;
+  unsigned int m_symtab_enabled : 1;
   run_time_clock::time_point m_start_cpu_time;
   std::chrono::steady_clock::time_point m_start_wall_time;
   long m_start_space;

base-commit: 76f8ef8d53792ef89aee7a51b94bc7d1cf324379
-- 
2.39.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gdb: some int to unsigned int conversion
  2023-01-21 14:56 [PATCH] gdb: some int to unsigned int conversion Enze Li
@ 2023-01-21 17:09 ` Tom Tromey
  2023-01-22  6:47   ` Enze Li
  2023-01-22  5:54 ` [PATCH v2] gdb: some int to bool conversion Enze Li
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-01-21 17:09 UTC (permalink / raw)
  To: Enze Li via Gdb-patches; +Cc: Enze Li, enze.li

>>>>> "Enze" == Enze Li via Gdb-patches <gdb-patches@sourceware.org> writes:

Enze> Work around this by using unsigned int instead.

Thank you, this is ok.

I tend to think we should switch to bool bitfields here instead (and
other spots avoiding bool), so if you want to do that, consider it
pre-approved.  For this sort of change we like to also change the
assignments to use true/false rather than 1/0.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] gdb: some int to bool conversion
  2023-01-21 14:56 [PATCH] gdb: some int to unsigned int conversion Enze Li
  2023-01-21 17:09 ` Tom Tromey
@ 2023-01-22  5:54 ` Enze Li
  2023-01-22 17:38   ` Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Enze Li @ 2023-01-22  5:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: enze.li

When building GDB with clang 16, I got this,

  CXX    maint.o
maint.c:1045:23: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_space_enabled = 1;
                      ^ ~
maint.c:1057:22: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_time_enabled = 1;
                     ^ ~
maint.c:1073:24: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
      m_symtab_enabled = 1;
                       ^ ~
3 errors generated.

Work around this by using bool bitfields instead.

Tested by rebuilding on x86_64-linux with clang 16 and gcc 12.
---
 gdb/maint.c | 12 ++++++------
 gdb/maint.h |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index 1a226bf75e30..52f91a3246fe 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1042,11 +1042,11 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
 #ifdef HAVE_USEFUL_SBRK
       char *lim = (char *) sbrk (0);
       m_start_space = lim - lim_at_start;
-      m_space_enabled = 1;
+      m_space_enabled = true;
 #endif
     }
   else
-    m_space_enabled = 0;
+    m_space_enabled = false;
 
   if (msg_type == 0 || per_command_time)
     {
@@ -1054,13 +1054,13 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
 
       m_start_cpu_time = run_time_clock::now ();
       m_start_wall_time = steady_clock::now ();
-      m_time_enabled = 1;
+      m_time_enabled = true;
 
       if (per_command_time)
 	print_time (_("command started"));
     }
   else
-    m_time_enabled = 0;
+    m_time_enabled = false;
 
   if (msg_type == 0 || per_command_symtab)
     {
@@ -1070,10 +1070,10 @@ scoped_command_stats::scoped_command_stats (bool msg_type)
       m_start_nr_symtabs = nr_symtabs;
       m_start_nr_compunit_symtabs = nr_compunit_symtabs;
       m_start_nr_blocks = nr_blocks;
-      m_symtab_enabled = 1;
+      m_symtab_enabled = true;
     }
   else
-    m_symtab_enabled = 0;
+    m_symtab_enabled = false;
 
   /* Initialize timer to keep track of how long we waited for the user.  */
   reset_prompt_for_continue_wait_time ();
diff --git a/gdb/maint.h b/gdb/maint.h
index 09a68c17befd..1741d1325677 100644
--- a/gdb/maint.h
+++ b/gdb/maint.h
@@ -49,9 +49,9 @@ class scoped_command_stats
   /* Track whether the stat was enabled at the start of the command
      so that we can avoid printing anything if it gets turned on by
      the current command.  */
-  int m_time_enabled : 1;
-  int m_space_enabled : 1;
-  int m_symtab_enabled : 1;
+  bool m_time_enabled : 1;
+  bool m_space_enabled : 1;
+  bool m_symtab_enabled : 1;
   run_time_clock::time_point m_start_cpu_time;
   std::chrono::steady_clock::time_point m_start_wall_time;
   long m_start_space;

base-commit: 52480b9ef499870c36c8dfb34df31e67df7bb4dd
-- 
2.39.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gdb: some int to unsigned int conversion
  2023-01-21 17:09 ` Tom Tromey
@ 2023-01-22  6:47   ` Enze Li
  0 siblings, 0 replies; 6+ messages in thread
From: Enze Li @ 2023-01-22  6:47 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Enze Li via Gdb-patches, enze.li

On Sat, Jan 21 2023 at 10:09:41 AM -0700, Tom Tromey wrote:

>>>>>> "Enze" == Enze Li via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Enze> Work around this by using unsigned int instead.
>
> Thank you, this is ok.
>

Hi Tom,

Thanks for your review.

I sent v2 of this patch to the @gdb-patches list.  Sorry for forgetting
to Cc you with your email address.  Maybe you could see it in this
thread.

Best Regards,
Enze

> I tend to think we should switch to bool bitfields here instead (and
> other spots avoiding bool), so if you want to do that, consider it
> pre-approved.  For this sort of change we like to also change the
> assignments to use true/false rather than 1/0.
>
> Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] gdb: some int to bool conversion
  2023-01-22  5:54 ` [PATCH v2] gdb: some int to bool conversion Enze Li
@ 2023-01-22 17:38   ` Tom Tromey
  2023-01-24  3:21     ` Enze Li
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-01-22 17:38 UTC (permalink / raw)
  To: Enze Li via Gdb-patches; +Cc: Enze Li, enze.li

>>>>> "Enze" == Enze Li via Gdb-patches <gdb-patches@sourceware.org> writes:

Enze> Work around this by using bool bitfields instead.

Thank you for doing this.
This is ok.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] gdb: some int to bool conversion
  2023-01-22 17:38   ` Tom Tromey
@ 2023-01-24  3:21     ` Enze Li
  0 siblings, 0 replies; 6+ messages in thread
From: Enze Li @ 2023-01-24  3:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Enze Li via Gdb-patches, enze.li

On Sun, Jan 22 2023 at 10:38:12 AM -0700, Tom Tromey wrote:

>>>>>> "Enze" == Enze Li via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Enze> Work around this by using bool bitfields instead.
>
> Thank you for doing this.
> This is ok.
>
> Tom

Thank you.  I'm checking this in now.

Enze

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-01-24  3:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21 14:56 [PATCH] gdb: some int to unsigned int conversion Enze Li
2023-01-21 17:09 ` Tom Tromey
2023-01-22  6:47   ` Enze Li
2023-01-22  5:54 ` [PATCH v2] gdb: some int to bool conversion Enze Li
2023-01-22 17:38   ` Tom Tromey
2023-01-24  3:21     ` Enze Li

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).