From patchwork Wed May 29 13:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1941270 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=HZNYD5FZ; 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 4Vq9mG4TGwz20Pr for ; Wed, 29 May 2024 23:51:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2260385ED69 for ; Wed, 29 May 2024 13:51:56 +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 832843858408 for ; Wed, 29 May 2024 13:51:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 832843858408 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 832843858408 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=1716990692; cv=none; b=CA0Y3HXn9MQKs2O6DQgKH2Hb1ur1uSzzpwlFwwdu9lQhZ+QlU1rj6YS+qdMTKeoOhzoNVU5vBpwFqzidkxWZelDI1deyNACOVMMl87RhaZ2c1NNUddpp8FTbtqhDqZ0Fe+X2yR50a69NHNfV1qN8Gh6FvbAsIQIGCxthpXHSuvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716990692; c=relaxed/simple; bh=4St8eYD5dOwPODFHG6ac2qdHJwS7tH7pmPUj0YQlky8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lFni6VOKkIbIjWe5wG04MWjaH2kTeQo8aJuI1nl8ko3pTdpcOFdwWnNCF9EbAun7nhMyvNF58F91fldauhTvbf1Rk6ZooxrmWof7T4y9ENIebPMQ8bBIjCmH/Oc1I2N7fhurNrp/wyckPOYtS4wUfelZCXzY5ddDB9XYT07Pu7o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716990690; 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: in-reply-to:in-reply-to:references:references; bh=w5ifzILGZXrV1hYDdWngSamENPPHICZCsGw3u3DHVr8=; b=HZNYD5FZuvDr7rszAHyPK3pXnaAh5jHTuxJzdrxjPquO53g7f5eTJaDWRKkq6G4EJXi+VL a08DJmffuzFWB9faJWyq3dtqvuC8PPQbsht2wDlcsEbDefx3PIm6xK9FpFR1035Exlk29B YFWP5cQ0K18jqWy2ONMwRrGmEh5qTe0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-169-QH8pYzLqOKmGttcrHtiJ3w-1; Wed, 29 May 2024 09:51:28 -0400 X-MC-Unique: QH8pYzLqOKmGttcrHtiJ3w-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-794e3b9d67dso74843885a.3 for ; Wed, 29 May 2024 06:51:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716990687; x=1717595487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w5ifzILGZXrV1hYDdWngSamENPPHICZCsGw3u3DHVr8=; b=KI9t/9Oc472O0FffM+YlEzCfsGFO6pyjNSNgp2im2VZKOkjDvJhmdUN0Qyx8um6ZmG G0wZK+p1TTiFKkf2j3vyWNShvUjx49wJ7ButIf3U1twmLdABce64hIxWDF0JziU8CO57 RhYNW9EI9lPYVhoinJWIDXdWjFUQbSNFgEnsRh0iLD62N+xbQFh7fu3bQK/9jDZ9a8LD fS3bNTu4slT9rQLeTx/jKO+kx7tnxxBfxVxj578wkQykoAWrTTp1jBbzFp/W/yjAQLBm L8Rpq1fCRuVDVGl7zppPxBep2HgeDGRlayX4WeliPnDDhEJ8oPmoSjbZzmEf7xgHP24f 4dqw== X-Gm-Message-State: AOJu0YwJZ25xK0UKVkMCjwRDdamu9x2++FkiEbk1BnlrMKdjd1FPEe5g UIF4gK+uN5n+0b3fIo8G+fB5Qzvo7YMqJms2AmcWoR26ltBdMLWg0yEGku7JQALhSOWH8bTxobz jabYFXtj9Nwok/iydAZlPTKNWAumeTTVDJzfCTN07bPz4dfUCW9XN4svgn+s1G9RrRXvkPqag1V LwKMLSVFeJL2sFgJjoi4paPztxJw37ld22w4s= X-Received: by 2002:a05:620a:8397:b0:794:782c:b0b0 with SMTP id af79cd13be357-794ab08683fmr1828866085a.8.1716990687408; Wed, 29 May 2024 06:51:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKHYcgtmpdOSLPXOgrTgBAd9HalSiKgokVLiwGuljAOs6V4bOfriHruLFZTR27nQYL5hmb1A== X-Received: by 2002:a05:620a:8397:b0:794:782c:b0b0 with SMTP id af79cd13be357-794ab08683fmr1828863085a.8.1716990686844; Wed, 29 May 2024 06:51:26 -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 af79cd13be357-794c87c3b06sm204480685a.73.2024.05.29.06.51.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:51:26 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: pragma target and static init [PR109753] Date: Wed, 29 May 2024 09:49:32 -0400 Message-ID: <20240529135125.611606-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <383fc850-1cea-41b9-b3e4-63fd646d37b2@redhat.com> References: <383fc850-1cea-41b9-b3e4-63fd646d37b2@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.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 Revised to drop the cgraph change so I can self-approve the remaining patch. Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- #pragma target and optimize should also apply to implicitly-generated functions like static initialization functions and defaulted special member functions. The handle_optimize_attribute change 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/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/cp/decl.cc | 3 +++ gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++ 3 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C base-commit: ff41abdca0ab9993b6170b9b1f46b3a40921f1b0 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/cp/decl.cc b/gcc/cp/decl.cc index a992d54dc8f..d481e1ec074 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17832,6 +17832,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;