From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 05B4B3833016; Fri, 6 Nov 2020 19:35:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05B4B3833016 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-4798] c++: Propagate attributes to clones in duplicate_decls [PR67453] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 556ab5125912fa2233986eb19d6cd995cf7de1d2 X-Git-Newrev: 6c282c14d1be0bba2bf5d49acd074b349f28ad17 Message-Id: <20201106193506.05B4B3833016@sourceware.org> Date: Fri, 6 Nov 2020 19:35:06 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Nov 2020 19:35:06 -0000 https://gcc.gnu.org/g:6c282c14d1be0bba2bf5d49acd074b349f28ad17 commit r11-4798-g6c282c14d1be0bba2bf5d49acd074b349f28ad17 Author: Jakub Jelinek 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 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&) { }