gdb: some int to unsigned int conversion

Message ID OS3P286MB215243E4429C6C8CD05AB540F0CA9@OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM
State Superseded
Headers
Series gdb: some int to unsigned int conversion |

Commit Message

Enze Li Jan. 21, 2023, 2:56 p.m. UTC
  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(-)


base-commit: 76f8ef8d53792ef89aee7a51b94bc7d1cf324379
  

Comments

Tom Tromey Jan. 21, 2023, 5:09 p.m. UTC | #1
>>>>> "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
  
Enze Li Jan. 22, 2023, 6:47 a.m. UTC | #2
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
  

Patch

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;