public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fix pdp11_expand_epilogue (PR target/107841)
@ 2023-07-13 16:47 Mikael Pettersson
  2023-07-13 17:46 ` Paul Koning
  2023-07-13 20:10 ` Paul Koning
  0 siblings, 2 replies; 5+ messages in thread
From: Mikael Pettersson @ 2023-07-13 16:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Paul Koning, Mikael Pettersson

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


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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 16:47 [PATCH] fix pdp11_expand_epilogue (PR target/107841) Mikael Pettersson
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

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