From patchwork Wed Apr 20 06:23:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1619323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YuCo/N/3; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4KjrGz6QGpz9sG0 for ; Wed, 20 Apr 2022 16:24:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E02C63857355 for ; Wed, 20 Apr 2022 06:24:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E02C63857355 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650435847; bh=87pMq6G8lf9zc2XNrka/kDUbadYUS0/HxAG1gHWXQoo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YuCo/N/3+s0OYX1GPlY5vBbq+vyXG2l0DLUK/Q0Qly8b6NnbV7R8SVeApRDcSG0IG FXdsJsfqHVXwJ9KG0CygNKNUMj8JKqjtuvLZPKvPBIIVtSoYN/hQN20ZdCJvtdIVGW cSxLp9m2sY9IWDyOCKf6IMVRefgFLqvssXJRibTM= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6D9D23858D3C for ; Wed, 20 Apr 2022 06:23:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D9D23858D3C Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-RtvQDA1yNEW5lfljJIQe2g-1; Wed, 20 Apr 2022 02:23:43 -0400 X-MC-Unique: RtvQDA1yNEW5lfljJIQe2g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 060C538041C4; Wed, 20 Apr 2022 06:23:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5A2CC44CDA; Wed, 20 Apr 2022 06:23:42 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 23K6Nde62376616 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 08:23:40 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 23K6NckI2376615; Wed, 20 Apr 2022 08:23:38 +0200 Date: Wed, 20 Apr 2022 08:23:38 +0200 To: Jan Hubicka , Richard Biener Subject: [PATCH] cgraph: Fix up semantic_interposition handling [PR105306] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! cgraph_node has a semantic_interposition flag which should mirror opt_for_fn (decl, flag_semantic_interposition). But it actually is initialized not from that, but from flag_semantic_interposition in the explicit symtab_node (symtab_type t) : type (t), resolution (LDPR_UNKNOWN), definition (false), alias (false), ... semantic_interposition (flag_semantic_interposition), ... x_comdat_group (NULL_TREE), x_section (NULL) {} ctor. I think that might be fine for varpool nodes, but since flag_semantic_interposition is now implied from -Ofast it isn't correct for cgraph nodes, unless we guarantee that cgraph node for a particular function decl is always created while that function is current_function_decl. That is often the case, but not always as the following function shows. Because symtab_node's ctor doesn't know for which decl the cgraph node is being created, the following patch keeps that as is, but updates it from opt_for_fn (decl, flag_semantic_interposition) when we know that, or for clones copies that flag (often it is then overridden in set_new_clone_decl_and_node_flags, but not always). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-04-20 Jakub Jelinek PR ipa/105306 * cgraph.cc (cgraph_node::create): Set node->semantic_interposition to opt_for_fn (decl, flag_semantic_interposition). * cgraphclones.cc (cgraph_node::create_clone): Copy over semantic_interposition flag. * g++.dg/opt/pr105306.C: New test. Jakub --- gcc/cgraph.cc.jj 2022-02-04 14:36:54.069618372 +0100 +++ gcc/cgraph.cc 2022-04-19 13:38:06.223782974 +0200 @@ -507,6 +507,7 @@ cgraph_node::create (tree decl) gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); node->decl = decl; + node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition); if ((flag_openacc || flag_openmp) && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl))) --- gcc/cgraphclones.cc.jj 2022-01-18 11:58:58.948991114 +0100 +++ gcc/cgraphclones.cc 2022-04-19 13:38:43.594262397 +0200 @@ -394,6 +394,7 @@ cgraph_node::create_clone (tree new_decl new_node->versionable = versionable; new_node->can_change_signature = can_change_signature; new_node->redefined_extern_inline = redefined_extern_inline; + new_node->semantic_interposition = semantic_interposition; new_node->tm_may_enter_irr = tm_may_enter_irr; new_node->externally_visible = false; new_node->no_reorder = no_reorder; --- gcc/testsuite/g++.dg/opt/pr105306.C.jj 2022-04-19 13:42:33.908054114 +0200 +++ gcc/testsuite/g++.dg/opt/pr105306.C 2022-04-19 13:42:08.859403045 +0200 @@ -0,0 +1,13 @@ +// PR ipa/105306 +// { dg-do compile } +// { dg-options "-Ofast" } + +#pragma GCC optimize 0 +template void foo (T); +struct B { ~B () {} }; +struct C { B f; }; +template struct E { + void bar () { foo (g); } + C g; +}; +template class E;