[gcc r17-2373] c++: Avoid duplicate trivial_abi cleanup in cdtor clones [PR125066]

Jason Merrill via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:513f02c7c565d6e874a6d57db30df87e7f3e2f37

commit r17-2373-g513f02c7c565d6e874a6d57db30df87e7f3e2f37
Author: Yuxuan Chen <[email protected]>
Date:   Mon Jul 13 21:34:25 2026 +0000

    c++: Avoid duplicate trivial_abi cleanup in cdtor clones [PR125066]
    
    Constructor and destructor clones already have a genericized copy of the
    original body, including parameter cleanups.  Do not add another front-end
    CLEANUP_STMT while processing a clone.
    
    gcc/cp/ChangeLog:
    
            PR c++/125066
            * decl.cc (store_parm_decls): Do not register trivial_abi parameter
            cleanups for cloned functions.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/125066
            * g++.dg/cpp0x/attr-trivial_abi10.C: New test.
    
    Signed-off-by: Yuxuan Chen <[email protected]>

Diff:
---
 gcc/cp/decl.cc                                  |  2 +-
 gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi10.C | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 6c5bb77e6031..340bbe71b9df 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -20276,7 +20276,7 @@ store_parm_decls (tree current_function_parms)
 
   /* Register cleanups for parameters with trivial_abi attribute, the cleanup
      of which is the callee's responsibility.  */
-  if (!processing_template_decl)
+  if (!processing_template_decl && !DECL_CLONED_FUNCTION_P (fndecl))
     for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
       {
 	if (TREE_CODE (parm) == PARM_DECL)
diff --git a/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi10.C b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi10.C
new file mode 100644
index 000000000000..5e0b2ffdf5ca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi10.C
@@ -0,0 +1,14 @@
+// PR c++/125066
+// { dg-do compile { target c++11 } }
+
+class Callback;
+struct Handler {
+  Handler(Callback);
+};
+struct [[clang::trivial_abi]] Holder {
+  ~Holder();
+};
+struct [[clang::trivial_abi]] Callback {
+  Holder holder;
+};
+Handler::Handler(Callback) {}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.