public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
@ 2022-11-23 16:57 avo2000 at mail dot ru
  2022-11-23 17:01 ` [Bug target/107841] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: avo2000 at mail dot ru @ 2022-11-23 16:57 UTC (permalink / raw)
  To: gcc-bugs

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))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/107841] Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
  2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
@ 2022-11-23 17:01 ` pinskia at gcc dot gnu.org
  2022-11-24 10:34 ` avo2000 at mail dot ru
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-23 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patches are submitted to gcc-patches@ after reading
https://gcc.gnu.org/contribute.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/107841] Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
  2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
  2022-11-23 17:01 ` [Bug target/107841] " pinskia at gcc dot gnu.org
@ 2022-11-24 10:34 ` avo2000 at mail dot ru
  2023-07-13 17:54 ` pkoning at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: avo2000 at mail dot ru @ 2022-11-24 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alexander <avo2000 at mail dot ru> ---
Source code:

void qq(int a) {
    char *s = alloca(128);
    sprintf(s,"qq %d",3);
}

Generated code:

0000040c <_qq>:
     40c:       1166            mov     r5, -(sp)
     40e:       1185            mov     sp, r5
     410:       65c6 ff80       add     $-200, sp
     414:       1180            mov     sp, r0
     416:       15e6 0003       mov     $3, -(sp)
     41a:       15e6 1868       mov     $14150, -(sp)
     41e:       1026            mov     r0, -(sp)
     420:       09f7 0326       jsr     pc, 74a <_sprintf>
     424:       65c6 0006       add     $6, sp
     428:       1585            mov     (sp)+, r5
     42a:       0087            rts     pc


The command "mov r5,sp" should be at the address 424

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/107841] Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
  2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
  2022-11-23 17:01 ` [Bug target/107841] " pinskia at gcc dot gnu.org
  2022-11-24 10:34 ` avo2000 at mail dot ru
@ 2023-07-13 17:54 ` pkoning at gcc dot gnu.org
  2023-07-13 20:09 ` cvs-commit at gcc dot gnu.org
  2023-07-13 20:11 ` pkoning at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pkoning at gcc dot gnu.org @ 2023-07-13 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

pkoning at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-07-13
             Status|UNCONFIRMED                 |ASSIGNED
                 CC|                            |pkoning at gcc dot gnu.org
     Ever confirmed|0                           |1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/107841] Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
  2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
                   ` (2 preceding siblings ...)
  2023-07-13 17:54 ` pkoning at gcc dot gnu.org
@ 2023-07-13 20:09 ` cvs-commit at gcc dot gnu.org
  2023-07-13 20:11 ` pkoning at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-13 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Koning <pkoning@gcc.gnu.org>:

https://gcc.gnu.org/g:8f1a26ee259f72e42405b9c5f2b161042ec4014b

commit r14-2509-g8f1a26ee259f72e42405b9c5f2b161042ec4014b
Author: Mikael Pettersson <mikpelinux@gmail.com>
Date:   Thu Jul 13 16:06:39 2023 -0400

    pdp11: Fix epilogue generation [PR107841]

    gcc/

            PR target/107841
            * config/pdp11/pdp11.cc (pdp11_expand_epilogue): Also
            deallocate alloca-only frame.

    gcc/testsuite/

            PR target/107841
            * gcc.target/pdp11/pr107841.c: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/107841] Incorrect generation of the function's epilogue code when there is a _builtin_alloca call.
  2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
                   ` (3 preceding siblings ...)
  2023-07-13 20:09 ` cvs-commit at gcc dot gnu.org
@ 2023-07-13 20:11 ` pkoning at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pkoning at gcc dot gnu.org @ 2023-07-13 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

pkoning at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #4 from pkoning at gcc dot gnu.org ---
Fixed by the patch from Mikael Petterson.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-13 20:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 16:57 [Bug c/107841] New: Incorrect generation of the function's epilogue code when there is a _builtin_alloca call avo2000 at mail dot ru
2022-11-23 17:01 ` [Bug target/107841] " pinskia at gcc dot gnu.org
2022-11-24 10:34 ` avo2000 at mail dot ru
2023-07-13 17:54 ` pkoning at gcc dot gnu.org
2023-07-13 20:09 ` cvs-commit at gcc dot gnu.org
2023-07-13 20:11 ` pkoning at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).