From patchwork Mon Sep 23 16:59:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1166156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509454-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jz6fxh9B"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46cVss4JBbz9sNw for ; Tue, 24 Sep 2019 02:59:27 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=J3T8aLdcnrNE4AmH9tPzYGflUv6zHsYVMx+fINDns8bi00ON/7 QY41+epVWuCI3+C1vgVTHIAuFZBVFMR5tGUWM2Fi5scax/xYgRo95X7QTe31yNMZ K1Dv5qTuJTcgNQLRJl63UT8/+b71XoYY1aIPHEPxyf8uXcpXxSZLKQwZM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=9r+PdCCg3wfVqcraQRO59lFGqHU=; b=jz6fxh9BPIaDjPKN+O36 d3MUMf2MXViseKR3rfo7m7p21mBd6iIHRv5IkUinzQZzPYVot3W3d+soFTbdbtWb PXpwqqV+siFZhHcFyN4sDKrPDLvAIs9yV/3wbI6ieJWI2SfZ0yRqtFusip1bHQlF 4RW4188yAJBhTN8xrF9hkUc= Received: (qmail 103143 invoked by alias); 23 Sep 2019 16:59:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 102871 invoked by uid 89); 23 Sep 2019 16:59:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=capability, originally, m_id, Copy X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Sep 2019 16:59:18 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0AD9BAE22 for ; Mon, 23 Sep 2019 16:59:16 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: [PR 91831] Copy PARM_DECLs of artificial thunks User-Agent: Notmuch/0.29.1 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Mon, 23 Sep 2019 18:59:15 +0200 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, I am quite surprised I did not catch this before but the new ipa-param-manipulation does not copy PARM_DECLs when creating artificial thinks (I think it originally did but then I somehow removed during one cleanups). Fixed below by adding the capability at the natural place. It is triggered whenever context of the PARM_DECL that is just taken from the original function does not match the target fndecl rather than by some constructor parameter because in such situation it is always the correct thing to do. Bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin 2019-09-23 Martin Jambor PR ipa/91831 * ipa-param-manipulation.c (carry_over_param): Make a method of ipa_param_body_adjustments, remove now unnecessary argument. Also copy in case of a context mismatch. (ipa_param_body_adjustments::common_initialization): Adjust call to carry_over_param. * ipa-param-manipulation.h (class ipa_param_body_adjustments): Add private method carry_over_param. testsuite/ * g++.dg/ipa/pr91831.C: New test. --- gcc/ipa-param-manipulation.c | 22 ++++++++++++++-------- gcc/ipa-param-manipulation.h | 1 + gcc/testsuite/g++.dg/ipa/pr91831.C | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr91831.C diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 7f52e9c2506..913b96fefa4 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -906,18 +906,24 @@ ipa_param_body_adjustments::register_replacement (ipa_adjusted_param *apm, m_replacements.safe_push (psr); } -/* Copy or not, as appropriate given ID, a pre-existing PARM_DECL T so that - it can be included in the parameters of the modified function. */ +/* Copy or not, as appropriate given m_id and decl context, a pre-existing + PARM_DECL T so that it can be included in the parameters of the modified + function. */ -static tree -carry_over_param (tree t, struct copy_body_data *id) +tree +ipa_param_body_adjustments::carry_over_param (tree t) { tree new_parm; - if (id) + if (m_id) { - new_parm = remap_decl (t, id); + new_parm = remap_decl (t, m_id); if (TREE_CODE (new_parm) != PARM_DECL) - new_parm = id->copy_decl (t, id); + new_parm = m_id->copy_decl (t, m_id); + } + else if (DECL_CONTEXT (t) != m_fndecl) + { + new_parm = copy_node (t); + DECL_CONTEXT (new_parm) = m_fndecl; } else new_parm = t; @@ -982,7 +988,7 @@ ipa_param_body_adjustments::common_initialization (tree old_fndecl, || apm->prev_clone_adjustment) { kept[prev_index] = true; - new_parm = carry_over_param (m_oparms[prev_index], m_id); + new_parm = carry_over_param (m_oparms[prev_index]); m_new_decls.quick_push (new_parm); } else if (apm->op == IPA_PARAM_OP_NEW diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h index 34477da51b7..8e9554563e4 100644 --- a/gcc/ipa-param-manipulation.h +++ b/gcc/ipa-param-manipulation.h @@ -370,6 +370,7 @@ public: private: void common_initialization (tree old_fndecl, tree *vars, vec *tree_map); + tree carry_over_param (tree t); unsigned get_base_index (ipa_adjusted_param *apm); ipa_param_body_replacement *lookup_replacement_1 (tree base, unsigned unit_offset); diff --git a/gcc/testsuite/g++.dg/ipa/pr91831.C b/gcc/testsuite/g++.dg/ipa/pr91831.C new file mode 100644 index 00000000000..66e4b693151 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr91831.C @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 --param uninlined-thunk-insns=1000" } */ + +struct A { + virtual void m_fn1(); +}; +struct B { + virtual void *m_fn2(int, int) = 0; +}; +struct C : A, B { + void *m_fn2(int, int) { return this; } +}; +void *fn1(B &p1) { return p1.m_fn2(0, 0); } + +int main() { + C c; + fn1(c); + return 0; +}