From patchwork Mon Dec 11 09:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 81883 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC4A83858413 for ; Mon, 11 Dec 2023 09:19:20 +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 E32993858D33 for ; Mon, 11 Dec 2023 09:19:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E32993858D33 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 E32993858D33 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=1702286345; cv=none; b=IRZdmFYpflJXMFr40HyMBfEH12PkJdYnLfSemJCjEFR3gioh1+chSrN7DHVz1wyun4nvWWfJwkoJeVK68c964nWm1EH6Ohx10LB2tPcDwDkQlha+pj1DT4H7g5Bm8PlzpHky3iYQFgIHdb3n1YSNxr5JGclwUjSzbZh5/JetOws= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702286345; c=relaxed/simple; bh=2rZprL7RFJgXknYc9/kIK4W/tPClc6a0QmQpGuon47o=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=kvfRcENrOfgJjiSm70RmBKRqrnjVQjh/WqI40VaBYDd9B9oZnFPxd5OAIBCbB3/k7msa1QjbrD5SGP51hrWVl8mT+fMQl3rU8mIV6VJDAV+uzkCTjT+K4ZWusT0E3cthwX+VfoeeQH1wiFoeoWNxBs3sPJp6NDVXe9pFEFBYyXU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 AF7482230C; Mon, 11 Dec 2023 09:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702286340; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=QrKF1iD7d3w0QlLo3InLWBXRfwduMZGQmqwwnTybG6s=; b=n9IWs2OVUqEQ1hqdLVzFm1HK9RqlU83wDYl5m1m/rw9HOPou9gtmxmLde8giuLFjeAOIIX 0zR9I3jV0KeILvKc+f/jfmqSj/4RaNsXBmqaw8fhsYypZfZBdwxBkVbyDMwP59NSxUGncy JB7uhcGKyb3nr5WhcjJxAirJ9Jz9ZWQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702286340; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=QrKF1iD7d3w0QlLo3InLWBXRfwduMZGQmqwwnTybG6s=; b=Z9kQpHOHYrv0EiWoMNjpx3VRcbJYGCNj23RW64VushwlDltBPaUdfxooyK2FFAJZUG0gWw i7n+5tOW98lV14Bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702286339; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=QrKF1iD7d3w0QlLo3InLWBXRfwduMZGQmqwwnTybG6s=; b=Phfoa9tGNIjHXe5Wlp5JnmzSLBtsTpbW6mhd9Rt+zrMiUV1ePncCjfhU15o2+QdBW+uesb GnswdF/vOlSlzRgziy3fZnBCYMMNYAQRL8Ciwu2NkDwG6Wc0cUXZR3zNG0Hpabojf0rYXZ i9lZzaXQgPKDAI551oPk0lfzp62L1xY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702286339; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=QrKF1iD7d3w0QlLo3InLWBXRfwduMZGQmqwwnTybG6s=; b=KoWiRdFG7XxYE/Hl1sdNO5hbVUmlUUwa1L88GCgMVVUhg5bnUtzGLiIpnBsKLSkYQaSyuN ADDX+TX2iI/FYNCQ== Date: Mon, 11 Dec 2023 10:17:58 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jan Hubicka , Jakub Jelinek Subject: [PATCH] ipa/92606 - properly handle no_icf attribute for variables MIME-Version: 1.0 X-Spam-Score: 8.20 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 1.20 X-Spamd-Result: default: False [1.20 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-0.998]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.994]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[27.79%] X-Spam-Flag: NO X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 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+patchwork=sourceware.org@gcc.gnu.org Message-Id: <20231211091920.EC4A83858413@sourceware.org> The following adds no_icf handling for variables where the attribute was rejected. It also fixes the check for no_icf by checking both the source and the targets decl. Bootstrap / regtest running on x86_64-unknown-linux-gnu. This would solve the AVR issue with merging of "progmem" attributed and non-"progmem" attributed variables if they'd also add no_icf there. OK? Thanks, Richard. PR ipa/92606 gcc/c-family/ * c-attribs.cc (handle_noicf_attribute): Also allow the attribute on global variables. gcc/ * ipa-icf.cc (sem_item_optimizer::merge_classes): Check both source and alias for the no_icf attribute. * doc/extend.texi (no_icf): Document variable attribute. --- gcc/c-family/c-attribs.cc | 3 ++- gcc/doc/extend.texi | 5 +++++ gcc/ipa-icf.cc | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 854e987dc79..a3671fe3a57 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -1649,7 +1649,8 @@ handle_noicf_attribute (tree *node, tree name, tree ARG_UNUSED (args), int ARG_UNUSED (flags), bool *no_add_attrs) { - if (TREE_CODE (*node) != FUNCTION_DECL) + if (TREE_CODE (*node) != FUNCTION_DECL + && (TREE_CODE (*node) != VAR_DECL || !is_global_var (*node))) { warning (OPT_Wattributes, "%qE attribute ignored", name); *no_add_attrs = true; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index e8b5e771f7a..f0c789f6cb4 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8152,6 +8152,11 @@ script to place the sections with the @code{.persistent} prefix in the right location. Specifically, some type of non-volatile, writeable memory is required. +@cindex @code{no_icf} variable attribute +@item no_icf +This variable attribute prevents a variable from being merged with another +equivalent variable. + @cindex @code{objc_nullability} variable attribute @item objc_nullability (@var{nullability kind}) @r{(Objective-C and Objective-C++ only)} This attribute applies to pointer variables only. It allows marking the diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc index 81232d5706e..e27536d73a9 100644 --- a/gcc/ipa-icf.cc +++ b/gcc/ipa-icf.cc @@ -3422,7 +3422,8 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count, alias->node->dump_asm_name ()); } - if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl))) + if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl)) + || lookup_attribute ("no_icf", DECL_ATTRIBUTES (source->decl))) { if (dump_enabled_p ()) dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc,