From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 8AF1D3858D1E for ; Mon, 1 May 2023 18:14:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8AF1D3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by gnu.wildebeest.org (Postfix, from userid 1000) id 8DC36302BB02; Mon, 1 May 2023 20:14:01 +0200 (CEST) Date: Mon, 1 May 2023 20:14:01 +0200 From: Mark Wielaard To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] xcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile. Message-ID: <20230501181401.GH3078@gnu.wildebeest.org> References: <20230429211342.1369527-1-mark@klomp.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-3036.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Simon, On Mon, May 01, 2023 at 09:53:39AM -0400, Simon Marchi wrote: > > Fix this by making main_subfile file static that is allocated and > > deallocated together with inclTable and allocate_include_entry and > > xcoff_symfile_finish. Adjust the use of main_subfile in > > process_linenos to take a pointer to the struct subfile. > > I'm not familiar at all with this code, but your change looks reasonable > to me. I am also not familiar with this code, but noticed that the fedora-latest and suse-tumbleweed buildbots started failing when they upgraded to GCC 13.1. The simplest solution seemed to be to give both structures the same lifetime. I didn't see any regressions with this fix (but don't actually know if the testsuite triggers this code). > Some style comments: > > > --- > > gdb/xcoffread.c | 24 +++++++++++++----------- > > 1 file changed, 13 insertions(+), 11 deletions(-) > > > > diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c > > index d71127b40f6..db6f2df6c0a 100644 > > --- a/gdb/xcoffread.c > > +++ b/gdb/xcoffread.c > > @@ -498,6 +498,9 @@ static int inclIndx; /* last entry to table */ > > static int inclLength; /* table length */ > > static int inclDepth; /* nested include depth */ > > > > +/* subfile structure for the main compilation unit. */ > > +static struct subfile *main_subfile; > > Remove "struct". OK. > > @@ -548,6 +551,7 @@ allocate_include_entry (void) > > inclTable = XCNEWVEC (InclTable, INITIAL_INCLUDE_TABLE_LENGTH); > > inclLength = INITIAL_INCLUDE_TABLE_LENGTH; > > inclIndx = 0; > > + main_subfile = new (struct subfile); > > "new subfile" would be enough. OK. > > for (int ii = 0; ii < inclIndx; ++ii) > > { > > - if (inclTable[ii].subfile != ((struct subfile *) &main_subfile) > > + if (inclTable[ii].subfile != ((struct subfile *) main_subfile) > > Since you touch this line, I think you could remove the cast. > main_subfile is already of the right type. Right. Will sent v2 with those changes. Thanks, Mark