public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-4798] c++: Propagate attributes to clones in duplicate_decls [PR67453]
Date: Fri,  6 Nov 2020 19:35:06 +0000 (GMT)	[thread overview]
Message-ID: <20201106193506.05B4B3833016@sourceware.org> (raw)

https://gcc.gnu.org/g:6c282c14d1be0bba2bf5d49acd074b349f28ad17

commit r11-4798-g6c282c14d1be0bba2bf5d49acd074b349f28ad17
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Nov 6 20:33:39 2020 +0100

    c++: Propagate attributes to clones in duplicate_decls [PR67453]
    
    On the following testcase where the cdtor attributes aren't on the
    in-class declaration but on an out-of-class definition, the cdtors
    have their clones created from the in-class declaration, and later on
    duplicate_decls updates attributes on the abstract cdtors, but nothing
    propagates them to the clones.
    
    2020-11-06  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/67453
            * decl.c (duplicate_decls): Propagate DECL_ATTRIBUTES and
            DECL_PRESERVE_P from olddecl to its clones if any.
    
            * g++.dg/ext/attr-used-2.C: New test.

Diff:
---
 gcc/cp/decl.c                          | 10 ++++++++++
 gcc/testsuite/g++.dg/ext/attr-used-2.C | 15 +++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 56bd772d01d..62648841ac3 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2921,6 +2921,16 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
 	snode->remove ();
     }
 
+  if (TREE_CODE (olddecl) == FUNCTION_DECL)
+    {
+      tree clone;
+      FOR_EACH_CLONE (clone, olddecl)
+	{
+	  DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
+	  DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
+	}
+    }
+
   /* Remove the associated constraints for newdecl, if any, before
      reclaiming memory. */
   if (flag_concepts)
diff --git a/gcc/testsuite/g++.dg/ext/attr-used-2.C b/gcc/testsuite/g++.dg/ext/attr-used-2.C
new file mode 100644
index 00000000000..d7cf6e975bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-used-2.C
@@ -0,0 +1,15 @@
+// PR c++/67453
+// { dg-do compile }
+// { dg-final { scan-assembler "_ZN1SC\[12]Ev" } }
+// { dg-final { scan-assembler "_ZN1SD\[12]Ev" } }
+// { dg-final { scan-assembler "_ZN1SC\[12]ERKS_" } }
+
+struct S {
+    S();
+    ~S();
+    S(const S&);
+};
+
+__attribute__((used)) inline S::S()  { }
+__attribute__((used)) inline S::~S() { }
+__attribute__((used)) inline S::S(const S&) { }


                 reply	other threads:[~2020-11-06 19:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201106193506.05B4B3833016@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).