From patchwork Fri Feb 24 09:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:7b8e:b0:9f:8c76:fea4 with SMTP id j14csp1221693dyk; Fri, 24 Feb 2023 01:37:13 -0800 (PST) X-Google-Smtp-Source: AK7set8jPXYw8uA30CcXiMcFoTm13b+xP2obyqF9IZO2WzE5wf5/XDFDRc8Yl9XNL2qEhoG7xe4G X-Received: by 2002:a05:6402:785:b0:4af:62ad:a36 with SMTP id d5-20020a056402078500b004af62ad0a36mr8525471edy.27.1677231433322; Fri, 24 Feb 2023 01:37:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677231433; cv=none; d=google.com; s=arc-20160816; b=powL/jXriil6NeKjn0daPmPQleixSvhSq3vR9iUqANIw6rUjfWv/NaHSN9XCnZqDh7 Lc5g/h6JEXynSoGZolOcTRYWd4W4M5N6wAlBv7J7y3GI3A2/QTUvQMjYwr7N6RjRaeKR 9deDBJ33kbB0+kfg6muBU/CR6vv/PpdXpQTLMe8Wxr16BfoeHkHSdzTcAD2SK2Jg4fBA r0EBzLAqS4MDqaGFtge1+CIciN0dPXVJv8ENNF1+UlDgz+cszTOYJXQcCIDcUKVKoh/9 TkUf31ojGCAZk5E6kjMsbclHys+m5Cocs7zprBWgB0vXenVrLcRpDpOAW+amXXuPVxNd ypRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=tvjW2GV4579cZ8bgfDdZhTEgT9/+wqcYNO479FYvhu8=; b=YClLT0ykgTL/2OaQkHKKbD0gQRWlB0Hc0J7IovHcbRLZSoK9QfI2rw6QKHfcQH9Bi2 tM6YWb11RxCHyrqMW5ZdGigDCG7xaMR+TZNXDMqDrr90rkWIq3qv/X77T0tTtM3VHBX2 7+/G/2A/MUM3nBFZgDu23MrJv+Pj2B96vjjnsTFpel9+EgXZgL47L7dJaNS1S/oiGiSh 7xDGazxg3/4T5kGHFqGrgNURn9w1tFWIqCqYHY4cp9VwIX7CrZvvGFfbTkCvjCbjdmrx zHkfrcQM7uBgnL1LM/ohDk66jxXgJPu/NrFvnB3YKB1Ue2pbh5xrUUQ+68XVpyp5iJc4 6i6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qV37XBA0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k13-20020aa7c38d000000b004acd26140b4si6399186edq.465.2023.02.24.01.37.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 01:37:13 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qV37XBA0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 040E638582B0 for ; Fri, 24 Feb 2023 09:37:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 040E638582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677231432; bh=tvjW2GV4579cZ8bgfDdZhTEgT9/+wqcYNO479FYvhu8=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qV37XBA0CR7QY+5kzD7pIFWJxufRzNPpGVdN5Csyws2iVq+EDKIGPU9mxhN6+16tY aZ3jAGfjGo1r3StrmVs4NMkv7Z0Dc90gRH94OuGSFVG5AZcPP9VXuditizM1bzd0hZ 458bPquwFWI5D3C0OF2LP6GQtQobSYs8Fx3Ejuh4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F30BC385842B for ; Fri, 24 Feb 2023 09:36:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F30BC385842B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-86-PAn8KkKmPBKsKKJqxo1P_A-1; Fri, 24 Feb 2023 04:36:23 -0500 X-MC-Unique: PAn8KkKmPBKsKKJqxo1P_A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2873183B3C6; Fri, 24 Feb 2023 09:36:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6435492B12; Fri, 24 Feb 2023 09:36:22 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31O9aKHR858062 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 24 Feb 2023 10:36:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31O9aIR3858061; Fri, 24 Feb 2023 10:36:18 +0100 Date: Fri, 24 Feb 2023 10:36:18 +0100 To: Richard Biener , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cgraphclones: Don't share DECL_ARGUMENTS between thunk and its artificial thunk [PR108854] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758704627543808321?= X-GMAIL-MSGID: =?utf-8?q?1758704627543808321?= Hi! The following testcase ICEs on x86_64-linux with -m32. The problem is we create an artificial thunk and because of -fPIC, ia32 and thunk destination which doesn't bind locally can't use a mi thunk. The ICE is because during expansion to RTL we see SSA_NAME for a PARM_DECL, but the PARM_DECL doesn't have DECL_CONTEXT of the current function. This is because duplicate_thunk_for_node creates a new DECL_ARGUMENTS chain only if some arguments need modification. The following patch fixes it by copying the DECL_ARGUMENTS list even if the arguments can stay as is, to update DECL_CONTEXT on them. While for mi thunks it doesn't really matter because we don't use those arguments in any way, for other thunks it is important. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-02-23 Jakub Jelinek PR middle-end/108854 * cgraphclones.cc (duplicate_thunk_for_node): If no parameter changes are needed, copy at least DECL_ARGUMENTS PARM_DECL nodes and adjust their DECL_CONTEXT. * g++.dg/opt/pr108854.C: New test. Jakub --- gcc/cgraphclones.cc.jj 2023-02-22 20:50:27.417519830 +0100 +++ gcc/cgraphclones.cc 2023-02-23 17:12:59.875133883 +0100 @@ -218,7 +218,17 @@ duplicate_thunk_for_node (cgraph_node *t body_adj.modify_formal_parameters (); } else - new_decl = copy_node (thunk->decl); + { + new_decl = copy_node (thunk->decl); + for (tree *arg = &DECL_ARGUMENTS (new_decl); + *arg; arg = &DECL_CHAIN (*arg)) + { + tree next = DECL_CHAIN (*arg); + *arg = copy_node (*arg); + DECL_CONTEXT (*arg) = new_decl; + DECL_CHAIN (*arg) = next; + } + } gcc_checking_assert (!DECL_STRUCT_FUNCTION (new_decl)); gcc_checking_assert (!DECL_INITIAL (new_decl)); --- gcc/testsuite/g++.dg/opt/pr108854.C.jj 2023-02-23 17:11:19.275583506 +0100 +++ gcc/testsuite/g++.dg/opt/pr108854.C 2023-02-23 17:11:02.723822009 +0100 @@ -0,0 +1,37 @@ +// PR middle-end/108854 +// { dg-do compile { target c++11 } } +// { dg-options "-O3" } +// { dg-additional-options "-fPIC" { target fpic } } + +struct A { A (int); ~A (); }; +struct B { B (int, bool); ~B (); }; +template +struct C { void m1 (T); void m2 (T &&); }; +class D; +struct E { virtual void m3 (); }; +template +struct F { virtual bool m4 (D &); }; +struct D { virtual D m5 () { return D (); } }; +void foo (void *, void *); +struct G { + int a; + C b; + void m4 (D &r) { B l (a, true); r.m5 (); b.m1 (&r); b.m2 (&r); } +}; +struct H : E, F { + template + H (int, T); + bool m4 (D &r) { A l (a); b.m4 (r); if (c) return true; } // { dg-warning "control reaches end of non-void function" } + int a; + bool c; + G b; +}; +inline void bar (F &p) { D s, t; p.m4 (t); foo (&p, &s); } +enum I { I1, I2 }; +template +struct J; +template +void baz () { int g = 0, h = 0; T i (g, h); bar (i); } +template +void qux () { baz > (); } +void corge () { qux (); qux (); }