From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QGGUJNQqAGWBzhQAWB0awg (envelope-from ) for ; Tue, 12 Sep 2023 05:09:40 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=gyo4O0Pr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 91C981E0C3; Tue, 12 Sep 2023 05:09:40 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 82E141E028 for ; Tue, 12 Sep 2023 05:09:38 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 020C53858412 for ; Tue, 12 Sep 2023 09:09:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 020C53858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694509778; bh=QfUo4gBMrsJjCH3FPxcmoK+QH9G0oyjoqczUEPkhrYQ=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=gyo4O0Pr5p5jRY+hdp9ftpD0FC+0OrekKMayPwe+aE5ZdLvaCAXDrXuObFsZtM/MM pS7DR3sT5ssrAy2oxkDqbM5Y1ttFFMKgzJxtL0yzFt0hNIU8mLSZviMr//0q66kRpT ZLonsRpWn8++5WAEBJFhw+ZPlNgBgUs2EuZwLKw0= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 5F9BC3858C50 for ; Tue, 12 Sep 2023 09:09:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F9BC3858C50 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4420D21857; Tue, 12 Sep 2023 09:09:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2AF6A139DB; Tue, 12 Sep 2023 09:09:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PeRJCbwqAGUhMAAAMHmgww (envelope-from ); Tue, 12 Sep 2023 09:09:16 +0000 Message-ID: <423cffbf-7fa4-4c08-8cd3-15bf4ae72c9f@suse.de> Date: Tue, 12 Sep 2023 11:09:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: Fix -Wuninitialied issue Content-Language: en-US To: Enze Li , gdb-patches@sourceware.org Cc: enze.li@gmx.com References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 9/12/23 10:22, Enze Li wrote: > I see the following warning when building GDB on FreeBSD/amd64 with > Clang 14, > > ====================================================================== > CXX mdebugread.o > mdebugread.c:1069:3: error: variable 'f' is uninitialized when used here [-Werror,-Wuninitialized] > f->set_loc_enumval (tsym.value); > ^ > mdebugread.c:836:17: note: initialize the variable 'f' to silence this warning > struct field *f; > ^ > = nullptr > ====================================================================== > > after digging a little, I realized that we can not simply do what > Clang 14 says. > > The root cause of this issue is that we lost the initialization of > the variable 'f' in this commit, > > commit 2774f2dad5f05e68771c07df6ab0fb23baa2118e > Date: Thu Aug 31 09:37:44 2023 +0200 > > [gdb/symtab] Factor out type::{alloc_fields,copy_fields} > Hi, thanks for fixing this. I've reviewed my commit once more, and only found the instance that this patch fixes. LGTM. Approved-By: Tom de Vries Thanks, - Tom > we have made these modifications, > > ---------------------------------------------------------------------- > --- a/gdb/mdebugread.c > +++ b/gdb/mdebugread.c > @@ -1034,9 +1034,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, > > t->set_code (type_code); > t->set_length (sh->value); > - t->set_num_fields (nfields); > - f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field))); > - t->set_fields (f); > + t->alloc_fields (nfields, false); > ---------------------------------------------------------------------- > > The problem is that the variable 'f' is used in the second half of > parse_symbol, that's why Clang complained. > > To fix this issue we need to ensure that the varibale 'f' is > initialized. Calling the fields method is an obvious way to fix this > issue. > > Tested on FreeBSD/amd64 by rebuilding. > --- > gdb/mdebugread.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c > index ea3e15be53b2..9cb30ce0acd0 100644 > --- a/gdb/mdebugread.c > +++ b/gdb/mdebugread.c > @@ -1035,6 +1035,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, > t->set_code (type_code); > t->set_length (sh->value); > t->alloc_fields (nfields); > + f = t->fields(); > > if (type_code == TYPE_CODE_ENUM) > { > > base-commit: 318d3bda5cad124bd11eebb0349d0f183ba625b1