Hi!

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.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2020-11-06  Jakub Jelinek  <ja...@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.

--- gcc/cp/decl.c.jj    2020-11-03 21:42:00.536043737 +0100
+++ gcc/cp/decl.c       2020-11-05 17:33:40.064072970 +0100
@@ -2921,6 +2921,16 @@ duplicate_decls (tree newdecl, tree oldd
        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)
--- gcc/testsuite/g++.dg/ext/attr-used-2.C.jj   2020-11-05 17:42:49.895949119 
+0100
+++ gcc/testsuite/g++.dg/ext/attr-used-2.C      2020-11-05 17:42:07.934416482 
+0100
@@ -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&) { }

        Jakub

Reply via email to