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

            Bug ID: 107841
           Summary: Incorrect generation of the function's epilogue code
                    when there is a _builtin_alloca call.
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: avo2000 at mail dot ru
  Target Milestone: ---

Incorrect generation of the function's epilogue code when there is a
_builtin_alloca call. The stack pointer is being restored incorrectly. The
function of the epilogue code generator pdp11_expand_epilogue () does not
handle the situation of having an alloca call.
Proposed solution:

--- pdp11.cc.bak        2022-08-19 11:09:52.684663800 +0300
+++ pdp11.cc    2022-11-23 19:09:11.908916500 +0300
@@ -392,7 +392,10 @@
   HOST_WIDE_INT fsize = get_frame_size ();
   unsigned regno;
   rtx x, reg, via_ac = NULL;
+  int can_trust_sp_p = !cfun->calls_alloca;

+  if (can_trust_sp_p)
+    {
   /* Deallocate the local variables.  */
   if (fsize)
     {
@@ -405,6 +408,14 @@
        emit_insn (gen_addhi3 (stack_pointer_rtx, stack_pointer_rtx,
                               GEN_INT (fsize)));
     }
+    }
+  else
+  /* Deallocate the areas allocated using the alloca call and local variables.
*/      
+       {
+         /* Deallocate the frame with a single move. */
+      gcc_assert (frame_pointer_needed);
+         emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
+       }

   /* Restore the FPU registers.  */
   if (pdp11_saved_regno (AC4_REGNUM) || pdp11_saved_regno (AC5_REGNUM))

Reply via email to