From patchwork Thu Dec 14 19:17:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1876364 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=ROqEKlRZ; 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 4SrhvG03XQz20H6 for ; Fri, 15 Dec 2023 06:17:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B6A438618BB for ; Thu, 14 Dec 2023 19:17:44 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9140A38618EF for ; Thu, 14 Dec 2023 19:17:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9140A38618EF 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 9140A38618EF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702581452; cv=none; b=O96ZKJTHaSkwXMm7YpLwJHM8ZoSEiZ65rlrPdmkDxHGGQkZk0vE1+Qk/0FaoWS8jCreiY/JS1fwPKbD6VfibxJiX01YEjpzBykCuSKwx/xsKkAJE0Yxc/zYAV1TgJl94D+YM9H8MXYyTvsDpYIIVOdeGCR7K1iQcGQvDnNfGezk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702581452; c=relaxed/simple; bh=WTbFrwIdExwCG50VgkyuwQYfMUAo4+Y8YTZmUcFlvek=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SNlo1oIzcQoSjTD2hx//Pr1qcLRWDP7bs21zoHq3DtLvUfsR0wKkNA9Q7hcGybMk2Ot+9tGnrroP2+MPsEOqawGNH3x6e2Ion4dUADRa+8MLR9NG7VfkkFRbER77/5MBQ1k6Zz6XY63+cKJ1exgA6EV506ZqOGqX8L1iUwgK9vU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702581451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=doDbJK7ZThaPIlf6Kdz0Mkt3vF+vnZmXzXMZaQJUI+8=; b=ROqEKlRZislKbyHbUcuo4YlZWunTuECgDr0Tyxo/p77JC5Yd1kVZWaSYc6VLbMK2Mii38f +9nrAC6N+ED/F+gIdTuHSJ/MyIvSapUI0IWFKPOwUoTIan6x5qeoM2iZi/sBS5FPFvFLP/ AYJXflbDC+5u70cLry756zBTRRGGkeI= 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-8-2OpE7ZYPMWOxPzUN72dMHA-1; Thu, 14 Dec 2023 14:17:30 -0500 X-MC-Unique: 2OpE7ZYPMWOxPzUN72dMHA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4257de8a5f4so108394641cf.2 for ; Thu, 14 Dec 2023 11:17:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702581448; x=1703186248; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=doDbJK7ZThaPIlf6Kdz0Mkt3vF+vnZmXzXMZaQJUI+8=; b=CjNcp9r4bkykYLNnmFVlsTstQEjJArlb8fsWyim1rUqc+03tEq5yriqsvPKWs2kItu kCb6/EGi5EvuQeNfZ8uD5NHhbmSOAFFtlfmZnCEICOoJ2YCmhnu24MVC+hwpmjRAzKxg xlvQ1LzTpVPAOeeU8442BfwXHojwjrLiDCSj+bIRv2d5mK45bKpneuEOy3+pr4wwAcTO QUuScVzcXPXK9aNJ7qClpPvz1EYjy82w8+nCjaDQkvll7KtoCx3kNNmTALOVcaPfdJW+ PMoJOmM93qXvdBfSx9aB60xR27Jp5eYRM1wkc963Sk4Sxy+j2RaoMVFaAZixaHQDWC+y y6pw== X-Gm-Message-State: AOJu0Yylvax2luRsvt1CbcN0z/JhpaKwf9280tiz7mnRlWecDaYHUvPH 7J42/L0P/h3a0OPEZQsMuLzZwVAf0eQPwFJSQ7lTutOFGKkD1oQbZIEtyabWU0GysJlahEdiNBi PwtXDx37yhJAk9O6THHodzTktK0Mxbi1qgh24p6gdPsxHMp4M+HKQh4l6sEKZvfmp7XxvIiNNVL Q= X-Received: by 2002:a05:622a:1895:b0:425:a982:b5f5 with SMTP id v21-20020a05622a189500b00425a982b5f5mr15460309qtc.94.1702581447990; Thu, 14 Dec 2023 11:17:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9lmB+Bi/pC+LtGxSCjUERmz0PTZBUd6xX6L6ATyH9W+YL7OQDBHF8D4OMbG5alGRqlPoV9A== X-Received: by 2002:a05:622a:1895:b0:425:a982:b5f5 with SMTP id v21-20020a05622a189500b00425a982b5f5mr15460290qtc.94.1702581447666; Thu, 14 Dec 2023 11:17:27 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f5-20020ac86ec5000000b0041ea59e639bsm6007629qtv.70.2023.12.14.11.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 11:17:27 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: section attribute on templates [PR70435, PR88061] Date: Thu, 14 Dec 2023 14:17:25 -0500 Message-ID: <20231214191725.1941372-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.76.g1a87c842ec MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_H3, 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- The section attribute currently has no effect on templates because the call to set_decl_section_name only happens at parse time and not also at instantiation time. This patch fixes this by propagating the section name from the template to the instantiation. PR c++/70435 PR c++/88061 gcc/cp/ChangeLog: * pt.cc (tsubst_function_decl): Call set_decl_section_name. (tsubst_decl) : Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-section1.C: New test. * g++.dg/ext/attr-section1a.C: New test. * g++.dg/ext/attr-section2.C: New test. * g++.dg/ext/attr-section2a.C: New test. --- gcc/cp/pt.cc | 4 ++++ gcc/testsuite/g++.dg/ext/attr-section1.C | 9 +++++++++ gcc/testsuite/g++.dg/ext/attr-section1a.C | 11 +++++++++++ gcc/testsuite/g++.dg/ext/attr-section2.C | 9 +++++++++ gcc/testsuite/g++.dg/ext/attr-section2a.C | 14 ++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/attr-section1.C create mode 100644 gcc/testsuite/g++.dg/ext/attr-section1a.C create mode 100644 gcc/testsuite/g++.dg/ext/attr-section2.C create mode 100644 gcc/testsuite/g++.dg/ext/attr-section2a.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 50e6f062c85..8c4174fb902 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -14607,6 +14607,8 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, = remove_attribute ("visibility", DECL_ATTRIBUTES (r)); } determine_visibility (r); + if (DECL_SECTION_NAME (t)) + set_decl_section_name (r, t); if (DECL_DEFAULTED_OUTSIDE_CLASS_P (r) && !processing_template_decl) defaulted_late_check (r); @@ -15423,6 +15425,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, = remove_attribute ("visibility", DECL_ATTRIBUTES (r)); } determine_visibility (r); + if (!local_p && DECL_SECTION_NAME (t)) + set_decl_section_name (r, t); } if (!local_p) diff --git a/gcc/testsuite/g++.dg/ext/attr-section1.C b/gcc/testsuite/g++.dg/ext/attr-section1.C new file mode 100644 index 00000000000..b8ac65baa93 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-section1.C @@ -0,0 +1,9 @@ +// PR c++/70435 +// { dg-do compile { target { c++11 && named_sections } } } + +template +[[gnu::section(".foo")]] void fun() { } + +template void fun(); + +// { dg-final { scan-assembler {.section[ \t]+.foo} } } diff --git a/gcc/testsuite/g++.dg/ext/attr-section1a.C b/gcc/testsuite/g++.dg/ext/attr-section1a.C new file mode 100644 index 00000000000..be24be2fc95 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-section1a.C @@ -0,0 +1,11 @@ +// PR c++/70435 +// { dg-do compile { target { c++11 && named_sections } } } + +template +struct A { + [[gnu::section(".foo")]] void fun() { } +}; + +template struct A; + +// { dg-final { scan-assembler {.section[ \t]+.foo} } } diff --git a/gcc/testsuite/g++.dg/ext/attr-section2.C b/gcc/testsuite/g++.dg/ext/attr-section2.C new file mode 100644 index 00000000000..a76f43b346f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-section2.C @@ -0,0 +1,9 @@ +// PR c++/88061 +// { dg-do compile { target { c++14 && named_sections } } } + +template +[[gnu::section(".foo")]] int var = 42; + +template int var; + +// { dg-final { scan-assembler {.section[ \t]+.foo} } } diff --git a/gcc/testsuite/g++.dg/ext/attr-section2a.C b/gcc/testsuite/g++.dg/ext/attr-section2a.C new file mode 100644 index 00000000000..a0b01cd8d93 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-section2a.C @@ -0,0 +1,14 @@ +// PR c++/88061 +// { dg-do compile { target { c++11 && named_sections } } } + +template +struct A { + [[gnu::section(".foo")]] static int var; +}; + +template +int A::var = 42; + +template struct A; + +// { dg-final { scan-assembler {.section[ \t]+.foo} } }