public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings
@ 2022-06-11 10:36 Enze Li
  2022-07-06 13:53 ` [PING] " Enze Li
  0 siblings, 1 reply; 4+ messages in thread
From: Enze Li @ 2022-06-11 10:36 UTC (permalink / raw)
  To: gdb-patches

On a machine with gcc 12, I get this warning:

  CXX    nat/linux-btrace.o
In function ‘btrace_error linux_read_bts(btrace_data_bts*, btrace_target_info*, btrace_read_type)’,
    inlined from ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-btrace.c:935:29:
../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used uninitialized [-Wmaybe-uninitialized]
  865 |   pevent->last_head = data_head;
      |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../gdb/nat/linux-btrace.c: In function ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’:
../gdb/nat/linux-btrace.c:792:9: note: ‘data_head’ was declared here
  792 |   __u64 data_head, data_tail;
      |         ^~~~~~~~~

Fix this by initializing the 'data_head' variable.

Tested by rebuilding on x86_64 openSUSE Tumbleweed with gcc 12.
---
 gdb/nat/linux-btrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
index b0d6dcd7cf1..c31fb5ffe43 100644
--- a/gdb/nat/linux-btrace.c
+++ b/gdb/nat/linux-btrace.c
@@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
   struct perf_event_buffer *pevent;
   const uint8_t *begin, *end, *start;
   size_t buffer_size, size;
-  __u64 data_head, data_tail;
+  __u64 data_head = 0, data_tail;
   unsigned int retries = 5;
 
   pevent = &tinfo->variant.bts.bts;
-- 
2.36.1


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

* [PING] [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings
  2022-06-11 10:36 [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings Enze Li
@ 2022-07-06 13:53 ` Enze Li
  2022-07-06 14:02   ` Metzger, Markus T
  0 siblings, 1 reply; 4+ messages in thread
From: Enze Li @ 2022-07-06 13:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: enze.li

Hi all,

Kindly PING for this tiny patch.  The warning mentioned in this patch
still exists in the trunk.  Does it make sense?

Best Regards,
Enze

On Sat, 2022-06-11 at 18:36 +0800, Enze Li via Gdb-patches wrote:
> On a machine with gcc 12, I get this warning:
> 
>   CXX    nat/linux-btrace.o
> In function ‘btrace_error linux_read_bts(btrace_data_bts*,
> btrace_target_info*, btrace_read_type)’,
>     inlined from ‘btrace_error linux_read_btrace(btrace_data*,
> btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-
> btrace.c:935:29:
> ../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used
> uninitialized [-Wmaybe-uninitialized]
>   865 |   pevent->last_head = data_head;
>       |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
> ../gdb/nat/linux-btrace.c: In function ‘btrace_error
> linux_read_btrace(btrace_data*, btrace_target_info*,
> btrace_read_type)’:
> ../gdb/nat/linux-btrace.c:792:9: note: ‘data_head’ was declared here
>   792 |   __u64 data_head, data_tail;
>       |         ^~~~~~~~~
> 
> Fix this by initializing the 'data_head' variable.
> 
> Tested by rebuilding on x86_64 openSUSE Tumbleweed with gcc 12.
> ---
>  gdb/nat/linux-btrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
> index b0d6dcd7cf1..c31fb5ffe43 100644
> --- a/gdb/nat/linux-btrace.c
> +++ b/gdb/nat/linux-btrace.c
> @@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
>    struct perf_event_buffer *pevent;
>    const uint8_t *begin, *end, *start;
>    size_t buffer_size, size;
> -  __u64 data_head, data_tail;
> +  __u64 data_head = 0, data_tail;
>    unsigned int retries = 5;
>  
>    pevent = &tinfo->variant.bts.bts;


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

* RE: [PING] [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings
  2022-07-06 13:53 ` [PING] " Enze Li
@ 2022-07-06 14:02   ` Metzger, Markus T
  2022-07-08 13:47     ` Enze Li
  0 siblings, 1 reply; 4+ messages in thread
From: Metzger, Markus T @ 2022-07-06 14:02 UTC (permalink / raw)
  To: Enze Li; +Cc: enze.li, gdb-patches

Hello Enze,

>> On a machine with gcc 12, I get this warning:
>>
>>   CXX    nat/linux-btrace.o
>> In function ‘btrace_error linux_read_bts(btrace_data_bts*,
>> btrace_target_info*, btrace_read_type)’,
>>     inlined from ‘btrace_error linux_read_btrace(btrace_data*,
>> btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-
>> btrace.c:935:29:
>> ../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used
>> uninitialized [-Wmaybe-uninitialized]
>>   865 |   pevent->last_head = data_head;
>>       |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

That's a false positive.  Since RETRIES > 0, the loop is executed at least
once and DATA_HEAD is initialized.


>> diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
>> index b0d6dcd7cf1..c31fb5ffe43 100644
>> --- a/gdb/nat/linux-btrace.c
>> +++ b/gdb/nat/linux-btrace.c
>> @@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
>>    struct perf_event_buffer *pevent;
>>    const uint8_t *begin, *end, *start;
>>    size_t buffer_size, size;
>> -  __u64 data_head, data_tail;
>> +  __u64 data_head = 0, data_tail;
>>    unsigned int retries = 5;
>>
>>    pevent = &tinfo->variant.bts.bts;

OK to pacify GCC.  Thanks for the patch.  LGTM.

regards,
markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

* Re: [PING] [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings
  2022-07-06 14:02   ` Metzger, Markus T
@ 2022-07-08 13:47     ` Enze Li
  0 siblings, 0 replies; 4+ messages in thread
From: Enze Li @ 2022-07-08 13:47 UTC (permalink / raw)
  To: Metzger, Markus T; +Cc: enze.li, gdb-patches

Hi Markus,

Thanks for your review.

On Wed, 2022-07-06 at 14:02 +0000, Metzger, Markus T wrote:
> Hello Enze,
> 
> > > On a machine with gcc 12, I get this warning:
> > > 
> > >   CXX    nat/linux-btrace.o
> > > In function ‘btrace_error linux_read_bts(btrace_data_bts*,
> > > btrace_target_info*, btrace_read_type)’,
> > >     inlined from ‘btrace_error linux_read_btrace(btrace_data*,
> > > btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-
> > > btrace.c:935:29:
> > > ../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be
> > > used
> > > uninitialized [-Wmaybe-uninitialized]
> > >   865 |   pevent->last_head = data_head;
> > >       |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
> 
> That's a false positive.  Since RETRIES > 0, the loop is executed at
> least
> once and DATA_HEAD is initialized.

Yeah, that's my understanding as well.

> 
> 
> > > diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c
> > > index b0d6dcd7cf1..c31fb5ffe43 100644
> > > --- a/gdb/nat/linux-btrace.c
> > > +++ b/gdb/nat/linux-btrace.c
> > > @@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts
> > > *btrace,
> > >    struct perf_event_buffer *pevent;
> > >    const uint8_t *begin, *end, *start;
> > >    size_t buffer_size, size;
> > > -  __u64 data_head, data_tail;
> > > +  __u64 data_head = 0, data_tail;
> > >    unsigned int retries = 5;
> > > 
> > >    pevent = &tinfo->variant.bts.bts;
> 
> OK to pacify GCC.  Thanks for the patch.  LGTM.

I'm checking this in now.

Thanks,
Enze

> 
> regards,
> markus.
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
> Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon
> Silva  
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928


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

end of thread, other threads:[~2022-07-08 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-11 10:36 [PATCH] gdb: initialize the data_head variable to eliminate compilation warnings Enze Li
2022-07-06 13:53 ` [PING] " Enze Li
2022-07-06 14:02   ` Metzger, Markus T
2022-07-08 13:47     ` 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).