From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 960873858C5F for ; Mon, 1 May 2023 13:53:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 960873858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.170] (unknown [167.248.160.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 280281E0D6; Mon, 1 May 2023 09:53:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1682949220; bh=0CuQOVWKR+6ghwlCTAHlpmLHPhqElA0on6oLieUJlKI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=CihdxFrrLxbl0eRH+NvWqcxdTwymBGzZ/pd1clb/uBu1iGVuU1awTLssZZoBAbafv NDuozgAKyL90TPJvesryP54S/T0Ecnntu7Cm16rBOQ5zLit8N8RROl4SM7w+R0J02E wXcKXUNabgUSDTLH6bI6ms0hCxbdiS5aoWDtN9O0= Message-ID: Date: Mon, 1 May 2023 09:53:39 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] xcoffread.c: Fix -Werror=dangling-pointer= issue with main_subfile. Content-Language: fr To: Mark Wielaard , gdb-patches@sourceware.org References: <20230429211342.1369527-1-mark@klomp.org> From: Simon Marchi In-Reply-To: <20230429211342.1369527-1-mark@klomp.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,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: On 4/29/23 17:13, Mark Wielaard wrote: > GCC 13 points out that main_subfile has local function scope, but a > pointer to it is assigned to the global inclTable array subfile > element field: > > In function ‘void process_linenos(CORE_ADDR, CORE_ADDR)’, > inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:727:19, > inlined from ‘void aix_process_linenos(objfile*)’ at xcoffread.c:720:1: > xcoffread.c:629:37: error: storing the address of local variable ‘main_subfile’ in ‘*inclTable.19_45 + _28._inclTable::subfile’ [-Werror=dangling-pointer=] > 629 | inclTable[ii].subfile = &main_subfile; > | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ > xcoffread.c: In function ‘void aix_process_linenos(objfile*)’: > xcoffread.c:579:18: note: ‘main_subfile’ declared here > 579 | struct subfile main_subfile; > | ^~~~~~~~~~~~ > xcoffread.c:496:19: note: ‘inclTable’ declared here > 496 | static InclTable *inclTable; /* global include table */ > | ^~~~~~~~~ > > 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. 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". > @@ -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. > 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. Simon