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: 65578 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3E60385B516 for ; Fri, 24 Feb 2023 09:36:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3E60385B516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677231416; 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=ssbZZuze48Dur36uUAdeErJRb3CyRKk17C1+XEWB8nVa5CpTXhE6QNRcNLOgeyW5Z Yydmal/MNCLR2DDoy8hFfKOrek+hyPluWpcsaAKscx3CqOX7PHnEZAEcZrMwNf/3nA TspSFn9kHLzEXkxW37mRvqstx+AVgMeE8T7fRzeo= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 (); }