From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tTvAALnQ4GqWnC8AWB0awg (envelope-from ) for ; Tue, 27 Oct 2026 12:26:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1793118392; bh=Ll1xCQZsLb2riewzrOEVhsED/S9BZfiJ00FcjTZgY98=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mBMtdyu9mrIFif52wTgVzwDWWGtnkJnrmDh9F8a3m8+rl4STnjEmEwyH/hMlY4fCh R9Czrc2d4nqEsGcA4AY+Pw19EWaKk+tx9ZfPfOBSrmtULW9Ll1wJ8+cn2f44A8pyx3 byutKYY98WfNNBEA5mqqGl379//sCDo31cPofjKI= Received: by simark.ca (Postfix, from userid 112) id DDFD11E007; Tue, 27 Oct 2026 12:26:32 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ff/g33AD; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E0FF91E007 for ; Tue, 27 Oct 2026 12:26:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 632B74BA23E3 for ; Tue, 27 Oct 2026 16:26:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 632B74BA23E3 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ff/g33AD Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2943F4BA23D6 for ; Tue, 27 Oct 2026 16:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2943F4BA23D6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2943F4BA23D6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793118360; cv=none; b=iKM19b43g///0vAsjJbn5MYZcLNwoVLltb2kR4L2/mO0DXr2DMGj9CHc1T0BS0Vv+aZZ6Hh0ZNOPzASHkmDSA7ahhw8rUdBcNU2ENez2HsYAXHu/iqFWhJ6fjAC2JEcrU5hN7cn1o1YRA7iugi0807t9bQbu6ZW0ubkCxxUQ0hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793118360; c=relaxed/simple; bh=Ll1xCQZsLb2riewzrOEVhsED/S9BZfiJ00FcjTZgY98=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=ZY/cqszEdQxuiuooYdhmkSw9KZpu6MezhoP2Vz63DOTo4Yc3Z4NY52DbouzFNtNmxe/AlolQIZFBVnUa1tcu4mxlLsmO8vs+iohVyFXs700njB6yvTLw05/mAXG0TW/iHqwIi30hk2HgnHYtWtR/i9O6MojIHHcpGpl7HRYLrsA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=ff/g33AD DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2943F4BA23D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1793118358; bh=Ll1xCQZsLb2riewzrOEVhsED/S9BZfiJ00FcjTZgY98=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ff/g33AD0KWcjJ6MPzZyfttt3zr/xrySszCLc0lpxBXW+gVWf1tUV/mgbmUU0NeYV OxAJpZjqm1m75BJgmFXpX+3M/FQtlPQUEHuL2/OlPbLkM9Rb5x0D2d3LXq0tSWHjYg vGJa4elIPiOKYjIRm/Hs1j8932dhC+MNH3mD5RbA= Received: by simark.ca (Postfix) id DFF361E007; Tue, 27 Oct 2026 12:25:58 -0400 (EDT) Message-ID: <12961fa5-a826-4823-97b6-2fce3e5bf19d@simark.ca> Date: Tue, 27 Oct 2026 12:25:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/build] Fix Wmaybe-uninitialized in tid_range_parser::get_tid_or_range To: Tom de Vries , gdb-patches@sourceware.org References: <20261027094926.2701072-1-tdevries@suse.de> Content-Language: fr From: Simon Marchi In-Reply-To: <20261027094926.2701072-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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