From patchwork Thu Mar 19 21:29:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1258478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48k0Rw211Sz9sPJ for ; Fri, 20 Mar 2020 08:30:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F4503945064; Thu, 19 Mar 2020 21:30:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 924EF385C017 for ; Thu, 19 Mar 2020 21:29:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 924EF385C017 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=hubicka@kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 73B762810C4; Thu, 19 Mar 2020 22:29:56 +0100 (CET) Date: Thu, 19 Mar 2020 22:29:56 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix cgraph_node::function_symbol availability computation [PR94202] Message-ID: <20200319212956.GA51205@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-23.7 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, this fixes ICE in inliner cache sanity check which is caused by very old bug in visibility calculation in cgraph_node::function_symbol and cgraph_node::function_or_virtual_thunk_symbol. In the testcase there is indirect call to a thunk. At begining we correctly see that its body as AVAIL_AVAILABLE but later we inline into the thunk and this turns it to AVAIL_INTERPOSABLE. This is because function_symbol incorrectly overwrites availability parameter by availability of the alias used in the call within thunk, which is a local alias. Bootstrap/regtest x86_64-linux in progress, plan to commit if succesfull. gcc/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/94202 * cgraph.c (cgraph_node::function_symbol): Fix availability computation. (cgraph_node::function_or_virtual_thunk_symbol): Likewise. gcc/testsuite/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/94202 * g++.dg/torture/pr94202.C: New test. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 9f0774f227f..b41dea1fcca 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -3788,16 +3788,13 @@ cgraph_node::function_symbol (enum availability *availability, while (node->thunk.thunk_p) { + enum availability a; + ref = node; node = node->callees->callee; - if (availability) - { - enum availability a; - a = node->get_availability (ref); - if (a < *availability) - *availability = a; - } - node = node->ultimate_alias_target (availability, ref); + node = node->ultimate_alias_target (availability ? &a : NULL, ref); + if (availability && a < *availability) + *availability = a; } return node; } @@ -3818,16 +3815,13 @@ cgraph_node::function_or_virtual_thunk_symbol while (node->thunk.thunk_p && !node->thunk.virtual_offset_p) { + enum availability a; + ref = node; node = node->callees->callee; - if (availability) - { - enum availability a; - a = node->get_availability (ref); - if (a < *availability) - *availability = a; - } - node = node->ultimate_alias_target (availability, ref); + node = node->ultimate_alias_target (availability ? &a : NULL, ref); + if (availability && a < *availability) + *availability = a; } return node; } diff --git a/gcc/testsuite/g++.dg/torture/pr94202.C b/gcc/testsuite/g++.dg/torture/pr94202.C new file mode 100644 index 00000000000..ab077368f9f --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr94202.C @@ -0,0 +1,21 @@ +struct S1 { + virtual ~S1(); + virtual void v(); +}; +struct S2: S1 {}; +struct S3: S1, S2 { void v(); }; +struct S4: S3 { void v(); }; +void S4::v() { S3::v(); } +struct R { + S1 * m; + void f(S2 * x) { + static_cast(x)->v(); + x->v(); + m = x; + } +}; +void f() { + R r; + r.f(new S4); + r.f(new S3); +}