public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Pettersson <mikpelinux@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: Paul Koning <ni1d@arrl.net>, Mikael Pettersson <mikpelinux@gmail.com>
Subject: [PATCH] fix pdp11_expand_epilogue (PR target/107841)
Date: Thu, 13 Jul 2023 18:47:57 +0200	[thread overview]
Message-ID: <20230713164756.3558785-2-mikpelinux@gmail.com> (raw)

If the stack frame only contains an alloca area, then
pdp11_expand_epilogue fails to deallocate it, resulting
in callee-saved registers and the return address being
restored from the wrong stack slots.  Fixed by adding
|| cfun->calls_alloca to the condition for deallocating
the frame.

Tested with a cross to pdp11-unknown-aout.

Ok for master? (Note: I don't have commit rights.)

gcc/

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

gcc/testsuite/

	PR target/107841
	* gcc.target/pdp11/pr107841.c: New test.
---
 gcc/config/pdp11/pdp11.cc                 |  2 +-
 gcc/testsuite/gcc.target/pdp11/pr107841.c | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/pdp11/pr107841.c

diff --git a/gcc/config/pdp11/pdp11.cc b/gcc/config/pdp11/pdp11.cc
index f6dd841f184..311a1d225e0 100644
--- a/gcc/config/pdp11/pdp11.cc
+++ b/gcc/config/pdp11/pdp11.cc
@@ -393,7 +393,7 @@ pdp11_expand_epilogue (void)
   rtx x, reg, via_ac = NULL;
 
   /* Deallocate the local variables.  */
-  if (fsize)
+  if (fsize || cfun->calls_alloca)
     {
       if (frame_pointer_needed)
 	{
diff --git a/gcc/testsuite/gcc.target/pdp11/pr107841.c b/gcc/testsuite/gcc.target/pdp11/pr107841.c
new file mode 100644
index 00000000000..a363c468b0b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/pdp11/pr107841.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* Verify that the stack frame is deallocated using the frame pointer.  */
+
+void qq (int a)
+{
+    char *s = __builtin_alloca (128);
+    __builtin_sprintf (s, "qq %d", 3);
+}
+
+/* { dg-final { scan-assembler "mov\tr5,sp" } } */
-- 
2.41.0


             reply	other threads:[~2023-07-13 16:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 16:47 Mikael Pettersson [this message]
2023-07-13 17:46 ` Paul Koning
2023-07-13 18:52   ` Jeff Law
2023-07-27 11:51     ` Maciej W. Rozycki
2023-07-13 20:10 ` Paul Koning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230713164756.3558785-2-mikpelinux@gmail.com \
    --to=mikpelinux@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ni1d@arrl.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).