https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108854

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think the problem is that duplicate_thunk_for_node when copying the
FUNCTION_DECL node doesn't also copy DECL_ARGUMENTS (unless some changes to the
arguments are needed).
--- gcc/cgraphclones.cc.jj      2023-02-22 20:50:27.417519830 +0100
+++ gcc/cgraphclones.cc 2023-02-23 16:02:29.653090584 +0100
@@ -218,7 +218,17 @@ duplicate_thunk_for_node (cgraph_node *t
       body_adj.modify_formal_parameters ();
     }
   else
-    new_decl = copy_node (thunk->decl);
+    {
+      new_decl = copy_node (thunk->decl);
+      for (tree *arg = &DECL_ARGUMENTS (new_decl);
+          *arg; arg = &DECL_CHAIN (*arg))
+       {
+         tree next = DECL_CHAIN (*arg);
+         *arg = copy_node (*arg);
+         DECL_CONTEXT (*arg) = new_decl;
+         DECL_CHAIN (*arg) = next;
+       }
+    }

   gcc_checking_assert (!DECL_STRUCT_FUNCTION (new_decl));
   gcc_checking_assert (!DECL_INITIAL (new_decl));
seems to fix the ICE.

Reply via email to