From patchwork Sun Oct 13 11:47:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1996522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=TWV9/h8l; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xGYrSPrw; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=TWV9/h8l; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=xGYrSPrw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XRJXX3r3lz1xv6 for ; Sun, 13 Oct 2024 22:48:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC5B2385AC29 for ; Sun, 13 Oct 2024 11:48:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id EAE2F3858C32 for ; Sun, 13 Oct 2024 11:47:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAE2F3858C32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EAE2F3858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728820081; cv=none; b=aHLxUdHVRFvhx9KwDxVjUNt2Qs1qVsxfxGSnTvWQ+2Y+7bQHwjTNFvWWS4Prn+S+gwKaRQe7n+YSr2WM7zCWlQiWmrOn/d3TYugHJSRy17ZS0vkYdNUwDNsjvXJvumWa86dCLv3JXFfMRwIbuAoapnCzptTXvrhplA62V24RC7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728820081; c=relaxed/simple; bh=0iBHvpN0XW2vHiYkghhqybVghHJPtYz2+31R/pup07Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=ZH7pGHdIfLJIvhFe4V5TXnOiRf6s/7UIB8yY7uRhADvNCBUSl7OM2mP79/9XfbUnBsddRXkSl582N5r+QdBCGDyNeXIqN9F4ccCnpPs612ZmXZv22flxVCfBdyCovXjhWBAw9E5TjesFZIecnoMWGH4nieob1cWFcUfHKIPR+4M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 998DC22059; Sun, 13 Oct 2024 11:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728820077; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E0FBiSWU3+oLz1EZqFXZEkRxHGpyal91UadKnMGDqos=; b=TWV9/h8lx4A6u0eJ6SMDsc8/ObLgm1F8Bbk8cRYW41CQJ9/woRDsnnUqnMgCyVCTRYyP3N E6JBqoJa1QY/h6GIyiSNsFiiHA13pC8L7fjRwsXjAVS3oH5uX/1maZeGaIdEo+ELApdntL udJMMQRL7FXfmLrMDQr4ttxGg/UMVnQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728820077; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E0FBiSWU3+oLz1EZqFXZEkRxHGpyal91UadKnMGDqos=; b=xGYrSPrw8tBdli7prdRCc0G2ai/r+KUKXYopEnGP4m+MLGfmDlslKqjeq0U1NFa08Zxbw0 pt7ehMF6mKSHA2AQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="TWV9/h8l"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=xGYrSPrw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728820077; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E0FBiSWU3+oLz1EZqFXZEkRxHGpyal91UadKnMGDqos=; b=TWV9/h8lx4A6u0eJ6SMDsc8/ObLgm1F8Bbk8cRYW41CQJ9/woRDsnnUqnMgCyVCTRYyP3N E6JBqoJa1QY/h6GIyiSNsFiiHA13pC8L7fjRwsXjAVS3oH5uX/1maZeGaIdEo+ELApdntL udJMMQRL7FXfmLrMDQr4ttxGg/UMVnQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728820077; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=E0FBiSWU3+oLz1EZqFXZEkRxHGpyal91UadKnMGDqos=; b=xGYrSPrw8tBdli7prdRCc0G2ai/r+KUKXYopEnGP4m+MLGfmDlslKqjeq0U1NFa08Zxbw0 pt7ehMF6mKSHA2AQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 749FF13306; Sun, 13 Oct 2024 11:47:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gUE6Gm2zC2dWPgAAD6G6ig (envelope-from ); Sun, 13 Oct 2024 11:47:57 +0000 Date: Sun, 13 Oct 2024 13:47:52 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/116907 - stale BLOCK reference from DECL_VALUE_EXPR MIME-Version: 1.0 Message-Id: <20241013114757.749FF13306@imap1.dmz-prg2.suse.org> X-Rspamd-Queue-Id: 998DC22059 X-Spam-Score: -4.51 X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; MISSING_XM_UA(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org When we remove unused BLOCKs we fail to clean references to them from DECL_VALUE_EXPRs of variables in other BLOCKs which in the PR causes LTO streaming to walk into pointers to GGC freed blocks. There's the question of whether such DECL_VALUE_EXPRs should keep variables and blocks referenced live (it doesn't seem to do that) and whether such DECL_VALUE_EXPRs should have survived in the first place. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR tree-optimization/116907 * tree-ssa-live.cc (clear_unused_block_pointer_in_block): New helper. (clear_unused_block_pointer): Call it. --- gcc/tree-ssa-live.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc index 0739faa022e..484698899cf 100644 --- a/gcc/tree-ssa-live.cc +++ b/gcc/tree-ssa-live.cc @@ -612,6 +612,22 @@ clear_unused_block_pointer_1 (tree *tp, int *, void *) return NULL_TREE; } +/* Clear references to unused BLOCKs from DECL_VALUE_EXPRs of variables + in BLOCK. */ + +static void +clear_unused_block_pointer_in_block (tree block) +{ + for (tree t = BLOCK_VARS (block); t; t = DECL_CHAIN (t)) + if (VAR_P (t) && DECL_HAS_VALUE_EXPR_P (t)) + { + tree val = DECL_VALUE_EXPR (t); + walk_tree (&val, clear_unused_block_pointer_1, NULL, NULL); + } + for (tree t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t)) + clear_unused_block_pointer_in_block (t); +} + /* Set all block pointer in debug or clobber stmt to NULL if the block is unused, so that they will not be streamed out. */ @@ -667,6 +683,10 @@ clear_unused_block_pointer (void) walk_tree (gimple_op_ptr (stmt, i), clear_unused_block_pointer_1, NULL, NULL); } + + /* Walk all variables mentioned in the functions BLOCK tree and clear + DECL_VALUE_EXPR from unused blocks where present. */ + clear_unused_block_pointer_in_block (DECL_INITIAL (current_function_decl)); } /* Dump scope blocks starting at SCOPE to FILE. INDENT is the