From patchwork Mon Mar 11 22:38:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1910764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=cnVYFAOp; 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 4TtsF75qxLz1yWn for ; Tue, 12 Mar 2024 09:40:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D12FE3858294 for ; Mon, 11 Mar 2024 22:40:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id B016C3858D34 for ; Mon, 11 Mar 2024 22:40:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B016C3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B016C3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710196836; cv=none; b=P0zWYNb1wrJ/RVr0Znumcz4SOlavuwBVjhcBcrEDImgKJBkUVLVZivpjFtBrleVzA6qMIQChoH8Rft70HyJzG/16YIAnIPV1BIs7vHan6OxKoiZYHRkn/WC9vKb87NSCcOLp0/n6BhLSCMmI3fuqu+sBHcy5Tk8XwtVwLtdnuyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710196836; c=relaxed/simple; bh=ifA2RHsRsgt5tDcgdIU2+mok+BSBXnhm0g6NjC6febY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l3J6qe3CUhkM6muLgXZDHrqeh2+WbGui858u8/fVdE/7d138npsLYQFcIW13vQ1+KGzaV78wZ08Ny1WyKLHsiqsfLfqBjDZwWdEO2ieGX2PEHHTVBjWpQzoot1y0Be4EL23qPqxzWxNTE2m9fLnrghdKuQaXTvVXwpb572nCsIE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33e5978fc1bso2128284f8f.3 for ; Mon, 11 Mar 2024 15:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1710196832; x=1710801632; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=VBO2nfJwa/y6lKL9JTDyMhn8T4dfN4V5sBxtLWncEVg=; b=cnVYFAOpif9vLRRF9gn5FMs1OyNcTC0UnJCsft/gOcpoou7ljngf8segFTNfECqotS H6pbTwaYlmJsV7AVpVb4wpIVIxl//Ve7uXNpb8H9N8fZFrVNsLI+06JHy7baIV0XPx5a qwrVPieeu3tqiJdKQdopCgO8MFUe6RE3WKyoZ4xnW6nX1XYBfZk3zJSFbSaxycPhrWuI pAOa1g3c1a+Xxh12HikQkiL3aBRiJFErVuhjJIaFuNuz6P6IDzF8huI1hnjmFbt4fAZK 4n2eJU2Sm6sS6s92qNjQV7upsYHevgxSExam0uAL28eK9adx9RqmMcE92uAQqMQx1oBs k5+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710196832; x=1710801632; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VBO2nfJwa/y6lKL9JTDyMhn8T4dfN4V5sBxtLWncEVg=; b=wWbHhy1D896a5xkUlZhfi/APjsZMaZPEJ6mX8l4MdMnhiWYOpHNzUYdyiMnLlqz9xH x2BHLPGbInIpzBMQ99+Akclp59FzWsWotpcUtAceASM+WZyDkSw0r9rDwm7zNNt+naEv x7DPjCzSEE2bBXrzYQSn01XLM4a7z/uds9Rs8BMQwqD06y19EZTsNnRgcFiuRnYZcHdo /ZJo7zowUi9HcFZzaYWCPnGe6qERF0OWRUP0i97hnbneVnnnUkWh6diMLBc8FTk0azJM IV0GxVaCusVolBEM71dhqjg7B9L3ww7Nxd2WH+WNkbwqKxtgpn/ZkJuiIsLguYy3hcTW rh8Q== X-Gm-Message-State: AOJu0YyOMep240j0jB/0vTOXNNQ2FP6Ur9Fgils/n1vd/q4HEQ0cehS8 dSL9XUmnX0D3m1t1PA9WQEZR93k8XsT8dLjiWOqclxFmdxDd+a1MZ6mm4utVihpi2NipUYqL/j4 = X-Google-Smtp-Source: AGHT+IGtDVPlxS5uaz7w+CefX04Ruk7G3PiAEvL7KqsThmbjUqGZ1O8bCRzcrDdipk+vkw6pixnUmg== X-Received: by 2002:a5d:64c8:0:b0:33e:64f3:65a5 with SMTP id f8-20020a5d64c8000000b0033e64f365a5mr312721wri.52.1710196832232; Mon, 11 Mar 2024 15:40:32 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id n8-20020a5d51c8000000b0033e6ede34d3sm7387417wrv.39.2024.03.11.15.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 15:40:31 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR ipa/113996 Date: Mon, 11 Mar 2024 23:38:54 +0100 Message-ID: <22214476.EfDdHjke4D@localhost.localdomain> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, this is a regression present on all active branches: the attached Ada testcase triggers an assertion failure when compiled with -O2 -gnatp -flto: /* Initialize the static chain. */ p = DECL_STRUCT_FUNCTION (fn)->static_chain_decl; gcc_assert (fn != current_function_decl); if (p) { /* No static chain? Seems like a bug in tree-nested.cc. */ gcc_assert (static_chain); <--- here setup_one_parameter (id, p, static_chain, fn, bb, &vars); } The problem is that the ICF pass identifies two functions, one of which has a static chain but the other does not. The proposed fix is just to prevent this identification from occurring. Tested on x86-64/Linux, OK for all active branches? 2024-03-11 Eric Botcazou PR ipa/113996 * ipa-icf.h (sem_function): Add static_chain_present member. * ipa-icf.cc (sem_function::get_hash): Hash it. (sem_function::equals_wpa): Compare it. (sem_function::equals_private): Likewise. (sem_function::init): Initialize it. 2024-03-11 Eric Botcazou * gnat.dg/lto27.adb: New test. diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc index 5d5a42f9c6c..dff7ad6efda 100644 --- a/gcc/ipa-icf.cc +++ b/gcc/ipa-icf.cc @@ -284,6 +284,7 @@ sem_function::get_hash (void) hstate.add_int (177454); /* Random number for function type. */ hstate.add_int (arg_count); + hstate.add_int (static_chain_present); hstate.add_int (cfg_checksum); hstate.add_int (gcode_hash); @@ -655,7 +656,10 @@ sem_function::equals_wpa (sem_item *item, } if (list1 || list2) - return return_false_with_msg ("Mismatched number of parameters"); + return return_false_with_msg ("mismatched number of parameters"); + + if (static_chain_present != m_compared_func->static_chain_present) + return return_false_with_msg ("static chain mismatch"); if (node->num_references () != item->node->num_references ()) return return_false_with_msg ("different number of references"); @@ -876,7 +880,10 @@ sem_function::equals_private (sem_item *item) return return_false (); } if (arg1 || arg2) - return return_false_with_msg ("Mismatched number of arguments"); + return return_false_with_msg ("mismatched number of arguments"); + + if (static_chain_present != m_compared_func->static_chain_present) + return return_false_with_msg ("static chain mismatch"); if (!dyn_cast (node)->has_gimple_body_p ()) return true; @@ -1368,6 +1375,8 @@ sem_function::init (ipa_icf_gimple::func_checker *checker) /* iterating all function arguments. */ arg_count = count_formal_params (fndecl); + static_chain_present = func->static_chain_decl != NULL_TREE; + edge_count = n_edges_for_fn (func); cgraph_node *cnode = dyn_cast (node); if (!cnode->thunk) diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h index ef7e41bfa88..bd9fd9fb294 100644 --- a/gcc/ipa-icf.h +++ b/gcc/ipa-icf.h @@ -355,6 +355,9 @@ public: parameters. */ bool compatible_parm_types_p (tree, tree); + /* Return true if parameter I may be used. */ + bool param_used_p (unsigned int i); + /* Exception handling region tree. */ eh_region region_tree; @@ -379,6 +382,9 @@ public: /* Total number of SSA names used in the function. */ unsigned ssa_names_size; + /* Whether the special PARM_DECL for the static chain is present. */ + bool static_chain_present; + /* Array of structures for all basic blocks. */ vec bb_sorted; @@ -386,9 +392,6 @@ public: function. */ hashval_t m_alias_sets_hash; - /* Return true if parameter I may be used. */ - bool param_used_p (unsigned int i); - private: /* Calculates hash value based on a BASIC_BLOCK. */ hashval_t get_bb_hash (const ipa_icf_gimple::sem_bb *basic_block);