> On Jul 13, 2023, at 12:47 PM, Mikael Pettersson <mikpeli...@gmail.com> wrote:
>
> 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
>
Thanks Mikael. I committed this fix.
paul