From patchwork Thu May 2 13:54:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1930627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yzl8mxp1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVbJ81tFjz20fb for ; Fri, 3 May 2024 00:03:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B53613858426 for ; Thu, 2 May 2024 14:03:32 +0000 (GMT) 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 EFB4A3858D20 for ; Thu, 2 May 2024 14:03:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFB4A3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFB4A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714658594; cv=none; b=l1fB1TqEwFVcsBo6ZrmjgoocqOX6CLV9xDwD2s5P0Y3/2YBUYXHdilKD+TULXaWXJgGeeqU+1cbvZlmRG+LbEPRrdgxd1k+jlFvf3T+//dPrGX8ori5hQicHHu2h3+yw84CcRKGq4sKrWlfmUPaMPljRLTDV1t+v3TwminFmWAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714658594; c=relaxed/simple; bh=JFmjnnbvzhhUCAhlyB47WcWGl7gktMndKJlq8Zf3Uwk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=efQF7DV0/P8hHjw6DXugalGKq8B5fRRdxv8TGUzJ4dW66RyubY3zoN+Lj8xjWd2vXGcsK1TBcA5uE7gTk9IcO8CpsK0DrEwBj27+PQba98N3OE0TxenC6WYvUKZZOAYNCqH/MICd9wCf7XkqTEEIaK6e9E5NmbuVM9E92m5f5ag= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714658583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OPvB3EfK1+PE3l+on7gB79Rk3L0pAw+r2tvU/mGZoJE=; b=Yzl8mxp1CxcdYUBg4j1T+FNN5b0Xz+wLU14oSJ9HT1i3bav7hSUzenrVZaIBOs+ASN1bxd uyLtf/Lk5HpddNprvL2y796WMZDuONXtd3SE2IOZIOigyqtnTSryLG6VWwrhKj39VcrZs6 mVen4SvxT5zDVsA5TW7+A5a4vgh33W4= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-503-Z6_7dmdENsOYln141uetQg-1; Thu, 02 May 2024 10:03:02 -0400 X-MC-Unique: Z6_7dmdENsOYln141uetQg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43a1389bc01so37619111cf.0 for ; Thu, 02 May 2024 07:02:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714658570; x=1715263370; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OPvB3EfK1+PE3l+on7gB79Rk3L0pAw+r2tvU/mGZoJE=; b=lOns9MrluJbjQwJfnWH9Ys8IRpaEOiEBTVRoJ2a4J43wsnj7XBJ/dm+ZudIzRwXdYh gM9eJg+l9AcdQzCgrLJD2Eei43wE/Pnit4m1ayc3GnTRJiOCtHjSujxZHgRA6n5gTDQ/ vK2sLC+bdPrq95f5Q7HeTkUP7O9BE0COheqK/u8KSckHFYb0EWu8fqlv4Ve6PK2pSXez 4iQxXMEPsLpR1QbnxryZniQiHf40mpzq8vsyzMZeN/TUdTACYdN5fQ6gppDXrTiEd5Dp ehoVwvHYjB/S5+ZJkWqBEkXO1jghaeiHPDVrqNCDvNZt+PI15EheoUqDyz40uhqaikYp +TWw== X-Gm-Message-State: AOJu0YyYpHGJMKhvQ9yxZfm50H6okrRHPN7DuTGeXj0YfGksE9knA8ec t8X6mKdQuv2NEwyv5Xp2s5eVX6d4hVkqsqh4CRCdtu5Zsjpz7G0ne5eky5kBA6b7IvSN6vCMWOo JTcUqDwiZh9kMRU4KWc+3gZN5rqRUIcMfQJk7pFfkPDP38wt7ltVLmsZ5BTLhupCTBYgeQ3qrOd xSQNybWR2z4WNJKawg2DcU0Ac3AScPEM3vqQQ= X-Received: by 2002:a05:622a:1352:b0:43b:6b9:a91a with SMTP id w18-20020a05622a135200b0043b06b9a91amr5090038qtk.12.1714658569380; Thu, 02 May 2024 07:02:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1qc7qVfWwqhPgMOgSKQ0O8WXD0ozmylHwpln/5zcXF5hRfoNvpMuA/fcaqYi6B7ovQwcCpg== X-Received: by 2002:a05:622a:1352:b0:43b:6b9:a91a with SMTP id w18-20020a05622a135200b0043b06b9a91amr5089993qtk.12.1714658568869; Thu, 02 May 2024 07:02:48 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id ea4-20020a05622a5b0400b0043c74447005sm503016qtb.33.2024.05.02.07.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 07:02:48 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org, Jan Hubicka Subject: [PATCH RFA (cgraph)] c++: pragma target and static init [PR109753] Date: Thu, 2 May 2024 09:54:22 -0400 Message-ID: <20240502140246.674422-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, OK for trunk? 14.2? This two-year-old thread seems relevant: https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html -- 8< -- #pragma target and optimize should also apply to implicitly-generated functions like static initialization functions and defaulted special member functions. At least one of the create_same_body_alias/handle_optimize_attribute changes is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body creates a cgraph_node for the ~B alias before handle_optimize_attribute, and the alias never goes through finalize_function, so we need to adjust semantic_interposition somewhere else. PR c++/109753 gcc/ChangeLog: * cgraph.cc (cgraph_node::create_same_body_alias): Set semantic_interposition. gcc/c-family/ChangeLog: * c-attribs.cc (handle_optimize_attribute): Set cgraph_node::semantic_interposition. gcc/cp/ChangeLog: * decl.cc (start_preparsed_function): Call decl_attributes. gcc/testsuite/ChangeLog: * g++.dg/opt/always_inline1.C: New test. --- gcc/c-family/c-attribs.cc | 4 ++++ gcc/cgraph.cc | 2 ++ gcc/cp/decl.cc | 3 +++ gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++ 4 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 04e39b41bdf..605469dd7dd 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args, if (prev_target_node != target_node) DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node; + /* Also update the cgraph_node, if it's already built. */ + if (cgraph_node *cn = cgraph_node::get (*node)) + cn->semantic_interposition = flag_semantic_interposition; + /* Restore current options. */ cl_optimization_restore (&global_options, &global_options_set, &cur_opts); diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..f3bd2fa8ece 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, tree decl) n = cgraph_node::create_alias (alias, decl); n->cpp_implicit_alias = true; + /* Aliases don't go through finalize_function. */ + n->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition); if (symtab->cpp_implicit_aliases_done) n->resolve_alias (cgraph_node::get (decl)); return n; diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 378311c0f04..4531d830462 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags) doing_friend = true; } + /* Adjust for #pragma target/optimize. */ + decl_attributes (&decl1, NULL_TREE, 0); + if (DECL_DECLARED_INLINE_P (decl1) && lookup_attribute ("noinline", attrs)) warning_at (DECL_SOURCE_LOCATION (decl1), 0, diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C new file mode 100644 index 00000000000..a042a1cf0c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C @@ -0,0 +1,8 @@ +// PR c++/109753 +// { dg-do compile { target x86_64-*-* } } + +#pragma GCC target("avx2") +struct aa { + __attribute__((__always_inline__)) aa() {} +}; +aa _M_impl;