From patchwork Thu Apr 30 14:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1280468 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49CdGz0lbbz9sSk for ; Fri, 1 May 2020 00:36:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 774BA395CC1E; Thu, 30 Apr 2020 14:36:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id CCD203898518 for ; Thu, 30 Apr 2020 14:36:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CCD203898518 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mjambor@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D5065AD31 for ; Thu, 30 Apr 2020 14:35:58 +0000 (UTC) From: Martin Jambor To: GCC Patches Subject: [PATCH] ipa: Cgraph verification fix (PR 94856) User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Thu, 30 Apr 2020 16:35:59 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-3052.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Cc: Jan Hubicka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, PR 94856 is a call graph verifier error. We have a method which (in the course of IPA-CP) loses its this pointer because it is unused and the pass then does not clone all the this adjusting thunks and just makes the calls go straight to the new clone - and then the verifier complains that the edge does not seem to point to a clone of what it used to. This looked weird because the verifier actually has logic detecting this case but it turns out that it is confused by inliner body-saving mechanism which invents a new decl for the base function. Making the inlining body-saving mechanism to correctly set former_clone_of allows us to detect this case too. Then we pass this particular round of verification but the subsequent one fails because we have inlined the function into its former thunk - which subsequently does not have any callees, but the verifier still access them and segfaults. Therefore the patch also adds a test whether the a former hunk even has any call. Passed bootstrap and testsuite on x86-64-linux, LTO bootstrap underway. OK for trunk (in time for GCC 10) if it passes it too? Thanks, Martin 2020-04-30 Martin Jambor PR ipa/94856 * cgraph.c (clone_of_p): Also consider thunks whih had their bodies saved by the inliner and thunks which had their call inlined. * ipa-inline-transform.c (save_inline_function_body): Fill in former_clone_of of new body holders. PR ipa/94856 * g++.dg/ipa/pr94856.C: New test. --- gcc/ChangeLog | 8 ++++++++ gcc/cgraph.c | 8 +++++--- gcc/ipa-inline-transform.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ipa/pr94856.C | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr94856.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ade7418401a..87f1f1af8f7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2020-04-30 Martin Jambor + + PR ipa/94856 + * cgraph.c (clone_of_p): Also consider thunks whih had their bodies + saved by the inliner and thunks which had their call inlined. + * ipa-inline-transform.c (save_inline_function_body): Fill in + former_clone_of of new body holders. + 2020-04-27 Jakub Jelinek PR target/94704 diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 72d7cb54301..2a9813df2d9 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -3104,15 +3104,17 @@ clone_of_p (cgraph_node *node, cgraph_node *node2) return false; /* In case of instrumented expanded thunks, which can have multiple calls in them, we do not know how to continue and just have to be - optimistic. */ - if (node->callees->next_callee) + optimistic. The same applies if all calls have already been inlined + into the thunk. */ + if (!node->callees || node->callees->next_callee) return true; node = node->callees->callee->ultimate_alias_target (); if (!node2->clone.param_adjustments || node2->clone.param_adjustments->first_param_intact_p ()) return false; - if (node2->former_clone_of == node->decl) + if (node2->former_clone_of == node->decl + || node2->former_clone_of == node->former_clone_of) return true; cgraph_node *n2 = node2; diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c index be60bbccb5c..e9e21cc0296 100644 --- a/gcc/ipa-inline-transform.c +++ b/gcc/ipa-inline-transform.c @@ -607,6 +607,8 @@ save_inline_function_body (struct cgraph_node *node) } } *ipa_saved_clone_sources->get_create (first_clone) = prev_body_holder; + first_clone->former_clone_of + = node->former_clone_of ? node->former_clone_of : node->decl; first_clone->clone_of = NULL; /* Now node in question has no clones. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abe97b9c0d5..4e12a77184a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-30 Martin Jambor + + PR ipa/94856 + * g++.dg/ipa/pr94856.C: New test. + 2020-04-26 Marek Polacek PR c++/90320 diff --git a/gcc/testsuite/g++.dg/ipa/pr94856.C b/gcc/testsuite/g++.dg/ipa/pr94856.C new file mode 100644 index 00000000000..5315c52d80e --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr94856.C @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-dse --param uninlined-function-insns=0 --param early-inlining-insns=3 -fgnu-tm " } */ + +class a { +public: + virtual ~a() {} +}; +class b { +public: + virtual void c(); +}; +class C : a, public b {}; +class d : C { + ~d(); + void c(); +}; +d::~d() { ((b *)this)->c(); } +void d::c() {}