Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/build] Fix Wmaybe-uninitialized in tid_range_parser::get_tid_or_range
Date: Tue, 27 Oct 2026 12:25:58 -0400	[thread overview]
Message-ID: <12961fa5-a826-4823-97b6-2fce3e5bf19d@simark.ca> (raw)
In-Reply-To: <20261027094926.2701072-1-tdevries@suse.de>

On 10/27/26 5:49 AM, Tom de Vries wrote:
> On aarch64-linux with an -O3 build, I run into:
> ...
> gdb/tid-parse.c: In function ‘int tid_is_in_list(const char*, int, int, int)’:
> gdb/tid-parse.c:375:39: warning: ‘tmp_thr_end’ may be used uninitialized \
>   [-Wmaybe-uninitialized]
>   374 |       if (tmp_inf == inf_num
>       |           ~~~~~~~~~~~~~~~~~~
>   375 |           && tmp_thr_start <= thr_num && thr_num <= tmp_thr_end)
>       |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
> gdb/tid-parse.c:370:35: note: ‘tmp_thr_end’ was declared here
>   370 |       int tmp_inf, tmp_thr_start, tmp_thr_end;
>       |                                   ^~~~~~~~~~~
> ...
> 
> This is a false positive.
> 
> The warning is triggered in the tail of function
> tid_range_parser::get_tid_or_range:
> ...
>   /* If we successfully parsed a thread number or finished parsing a
>      thread range, switch back to assuming the next TID is
>      inferior-qualified.  */
>   if (!m_range_parser.in_range ())
>     {
>       m_state = STATE_INFERIOR;
>       m_cur_tok = m_range_parser.cur_tok ();
> 
>       if (thr_end != NULL)
> 	*thr_end = *thr_start;
>     }
> 
>   /* If we're midway through a range, and the caller wants the end
>      value, return it and skip to the end of the range.  */
>   if (thr_end != NULL
>       && (m_state == STATE_THREAD_RANGE
>           || m_state == STATE_STAR_RANGE))
>     {
>       *thr_end = m_range_parser.end_value ();
> 
>       skip_range ();
>     }
> 
>   return (*inf_num != 0 && *thr_start != 0);
> }
> ...
> 
> To understand what's happening, we need to know two things:
> - m_state has enum type with 3 valid values: STATE_INFERIOR,
>   STATE_THREAD_RANGE, STATE_STAR_RANGE, and
> - at the start of the code snippet, m_state != STATE_INFERIOR.
> 
> The first lets us reduce this:
> ...
>   if (thr_end != NULL
>       && (m_state == STATE_THREAD_RANGE
>           || m_state == STATE_STAR_RANGE))
> ...
> to:
> ...
>   if (thr_end != NULL && m_state != STATE_INFERIOR)
> ...
> 
> The second lets us reduce it to:
> ...
>   else if (thr_end != NULL)
> ...
> at which point the warning is no longer triggered.
> 
> And if we copy the return to the first if clause, we simply get:
> ...
>   if (thr_end != NULL)
> ...
> 
> Do this simplification and get rid of the warning.
> 
> Tested on aarch64-linux.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34892

Ok, I think I followed that, with the new structure it's more obvious to
the compiler that *thr_end is always set (if thr_end != nullptr).

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

      reply	other threads:[~2026-10-27 16:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  9:49 Tom de Vries
2026-10-27 16:25 ` Simon Marchi [this message]

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=12961fa5-a826-4823-97b6-2fce3e5bf19d@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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