]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Propagate attributes to clones in duplicate_decls [PR67453]
authorJakub Jelinek <jakub@redhat.com>
Fri, 6 Nov 2020 19:33:39 +0000 (20:33 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 12 Nov 2020 10:03:44 +0000 (11:03 +0100)
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.

(cherry picked from commit 6c282c14d1be0bba2bf5d49acd074b349f28ad17)

gcc/cp/decl.c
gcc/testsuite/g++.dg/ext/attr-used-2.C [new file with mode: 0644]

index a88f32364cfc2064d21a1ec018ca580100ed7545..a84ac8cd4b2718b04172d83e55cc753b1d8167ee 100644 (file)
@@ -2899,6 +2899,16 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
        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 (file)
index 0000000..d7cf6e9
--- /dev/null
@@ -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&) { }