From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id JM6ZH0wrAGW1zhQAWB0awg (envelope-from ) for ; Tue, 12 Sep 2023 05:11: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=gaEruY1z; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 786631E0C3; Tue, 12 Sep 2023 05:11:40 -0400 (EDT) Received: from server2.sourceware.org (server2.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 6AF2A1E028 for ; Tue, 12 Sep 2023 05:11:38 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D93153858417 for ; Tue, 12 Sep 2023 09:11:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D93153858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694509897; bh=mFeic+IfqOSUwt/iWDP2B29zr+TUCFcfELSL4LN6RYo=; 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=gaEruY1z6uxaIn2NZOKk66ZOXd6WnYk1BnuwBx3RyK82JYbVEwvez/1/wCauW+IN5 kIN+z8YqLQEqhjOjXVD47jyL1L3B/2CMqLZuB3xXVrBJxjy88/m9wg7zNgcxHgCEEZ QuHg4frZxDL84lRi0NypuXoo4ewqC1iQWl4nnj0E= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 5DC9D3858C50 for ; Tue, 12 Sep 2023 09:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DC9D3858C50 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 76FAA2166E; Tue, 12 Sep 2023 09:11:17 +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 5E6D3139DB; Tue, 12 Sep 2023 09:11:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ydjoFTUrAGUxMQAAMHmgww (envelope-from ); Tue, 12 Sep 2023 09:11:17 +0000 Message-ID: Date: Tue, 12 Sep 2023 11:11:05 +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: <423cffbf-7fa4-4c08-8cd3-15bf4ae72c9f@suse.de> In-Reply-To: <423cffbf-7fa4-4c08-8cd3-15bf4ae72c9f@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, BODY_8BITS, 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 11:09, Tom de Vries via Gdb-patches wrote: > 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 > Forgot to mention: before pushing, please fix the typo in $subject: Wuninitialied -> Wuninitialized. 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 >