From patchwork Fri Jul 26 11:54:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1965283 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.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=nEJJRbf5; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=POezOlxO; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=nEJJRbf5; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=POezOlxO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WVmR272GQz1yXx for ; Fri, 26 Jul 2024 21:55:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B164382DC70 for ; Fri, 26 Jul 2024 11:55:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id B9F163865C2C for ; Fri, 26 Jul 2024 11:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9F163865C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B9F163865C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721994903; cv=none; b=lHEkjM2FbIz74d1F1Y6nSqboa0QOAI25o6GsNCMUrEfscvpbB0T0kipRONxcPzA78j1nfCMqL7DdQgI1O2VN75Tn6qRFXM8D4aAHm3SXgaSYsOT8wzClNX/hzPqfK0Avc/uAGALpsa1Uggt/o1KPK2JpjIjPbO7j16Pqxf9nckw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721994903; c=relaxed/simple; bh=Za5ZqJruZORBnD3p3KPfc0umq8cm8NfjYy7lDWLWLC4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=LIEuxZedSt2zT/Zx3CBTlX7QtL3lZVd4JeKZ8og159aObHRFZQo+xcNUDM1cHYDtk8WsuZ5+hfH2Wmv93MGx3Vzn8DefJ8LZofiLjXnALTDVnMiX2PZ0dhzwGFyUtNB6aD46mDhTWo9Q8GJjkP8EssN3SfF1DP6SoYYBVZb8nac= 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-out2.suse.de (Postfix) with ESMTPS id 85E921F898; Fri, 26 Jul 2024 11:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721994900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZtIXjYSQB9d+lb5GJmPuQovxwFuWgewMIPZE+dTzyHE=; b=nEJJRbf5wyfUECpDk+hQ4WoCb/JCbnkEr1ESqwx/W2IiUcRybI3Cv1ewE33VKEFcpzlLjG MqL98R2DogC5hzgZ2pSl251MrDLelOpGde+ZfKfvtoDD4DvdnshIrOGtWLOLlSC8wX0Edp YR/VLz8KH9fNPRlQfnVZ+KwreG+IIRs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721994900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZtIXjYSQB9d+lb5GJmPuQovxwFuWgewMIPZE+dTzyHE=; b=POezOlxOWyIkYvGXsM/PXcam5XGctPwyXMzn7llLl1eW+0DzAWChJ094iDgETOVIUBYdRs EH9DR186kV6KyYDQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=nEJJRbf5; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=POezOlxO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1721994900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZtIXjYSQB9d+lb5GJmPuQovxwFuWgewMIPZE+dTzyHE=; b=nEJJRbf5wyfUECpDk+hQ4WoCb/JCbnkEr1ESqwx/W2IiUcRybI3Cv1ewE33VKEFcpzlLjG MqL98R2DogC5hzgZ2pSl251MrDLelOpGde+ZfKfvtoDD4DvdnshIrOGtWLOLlSC8wX0Edp YR/VLz8KH9fNPRlQfnVZ+KwreG+IIRs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1721994900; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZtIXjYSQB9d+lb5GJmPuQovxwFuWgewMIPZE+dTzyHE=; b=POezOlxOWyIkYvGXsM/PXcam5XGctPwyXMzn7llLl1eW+0DzAWChJ094iDgETOVIUBYdRs EH9DR186kV6KyYDQ== 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 790061396E; Fri, 26 Jul 2024 11:55:00 +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 nmjyG5SOo2ascAAAD6G6ig (envelope-from ); Fri, 26 Jul 2024 11:55:00 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 1/2] ipa: Treat static constructors and destructors as non-local (PR 115815) User-Agent: Notmuch/0.38.3 (https://notmuchmail.org) Emacs/29.4 (x86_64-suse-linux-gnu) Date: Fri, 26 Jul 2024 13:54:59 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.31 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; TO_DN_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[suse.cz:+] X-Rspamd-Action: no action X-Spam-Score: -4.31 X-Rspamd-Queue-Id: 85E921F898 X-Spam-Status: No, score=-11.6 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 Hi, in PR 115815, IPA-SRA thought it had control over all invocations of a (recursive) static destructor but it did not see the implied invocation which led to the original being left behind and the clean-up code encountering uses of SSAs that definitely should have been dead. Fixed by teaching cgraph_node::can_be_local_p about static constructors and destructors. Similar test is missing in cgraph_node::local_p so I added the check there as well. Bootstrapped and tested on x86_64-linux. OK for master and after a while to gcc14 and gcc13 release branches? Thanks, Martin gcc/ChangeLog: 2024-07-25 Martin Jambor PR ipa/115815 * cgraph.cc (cgraph_node_cannot_be_local_p_1): Also check DECL_STATIC_CONSTRUCTOR and DECL_STATIC_DESTRUCTOR. * ipa-visibility.cc (non_local_p): Likewise. (cgraph_node::local_p): Delete extraneous line of tabs. gcc/testsuite/ChangeLog: 2024-07-25 Martin Jambor PR ipa/115815 * gcc.dg/lto/pr115815_0.c: New test. --- gcc/cgraph.cc | 4 +++- gcc/ipa-visibility.cc | 5 +++-- gcc/testsuite/gcc.dg/lto/pr115815_0.c | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/lto/pr115815_0.c diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..39a3adbc7c3 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -2434,7 +2434,9 @@ cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *) && !node->forced_by_abi && !node->used_from_object_file_p () && !node->same_comdat_group) - || !node->externally_visible)); + || !node->externally_visible) + && !DECL_STATIC_CONSTRUCTOR (node->decl) + && !DECL_STATIC_DESTRUCTOR (node->decl)); } /* Return true if cgraph_node can be made local for API change. diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc index 501d3c304aa..21f0c47f388 100644 --- a/gcc/ipa-visibility.cc +++ b/gcc/ipa-visibility.cc @@ -102,7 +102,9 @@ non_local_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) && !node->externally_visible && !node->used_from_other_partition && !node->in_other_partition - && node->get_availability () >= AVAIL_AVAILABLE); + && node->get_availability () >= AVAIL_AVAILABLE + && !DECL_STATIC_CONSTRUCTOR (node->decl) + && !DECL_STATIC_DESTRUCTOR (node->decl)); } /* Return true when function can be marked local. */ @@ -116,7 +118,6 @@ cgraph_node::local_p (void) return n->callees->callee->local_p (); return !n->call_for_symbol_thunks_and_aliases (non_local_p, NULL, true); - } /* A helper for comdat_can_be_unshared_p. */ diff --git a/gcc/testsuite/gcc.dg/lto/pr115815_0.c b/gcc/testsuite/gcc.dg/lto/pr115815_0.c new file mode 100644 index 00000000000..d938ae4c802 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr115815_0.c @@ -0,0 +1,18 @@ +int a; +volatile int v; +volatile int w; + +int __attribute__((destructor)) +b() { + if (v) + return a + b(); + v = 5; + return 0; +} + +int +main (int argc, char **argv) +{ + w = 1; + return 0; +}