On Wed, Mar 14, 2018 at 05:40:49PM +0000, Sudi Das wrote: > Hi > > This patch is another partial fix for PR 84521. This is adding a > definition to one of the target hooks used in the SJLJ implemetation so > that AArch64 defines the hard_frame_pointer_rtx as the > TARGET_BUILTIN_SETJMP_FRAME_VALUE. As pointed out by Wilco there is > still a lot more work to be done for these builtins in the future. > > Testing: Bootstrapped and regtested on aarch64-none-linux-gnu and added > new test. > > Is this ok for trunk?
OK. Thanks, James > *** gcc/ChangeLog *** > > 2018-03-14 Sudakshina Das <sudi....@arm.com> > > * builtins.c (expand_builtin_setjmp_receiver): Update condition > to restore frame pointer. > * config/aarch64/aarch64.h (DONT_USE_BUILTIN_SETJMP): Update > comment. > * config/aarch64/aarch64.c (aarch64_builtin_setjmp_frame_value): > New. > (TARGET_BUILTIN_SETJMP_FRAME_VALUE): Define. > > *** gcc/testsuite/ChangeLog *** > > 2018-03-14 Sudakshina Das <sudi....@arm.com> > > * gcc.c-torture/execute/pr84521.c: New test. > diff --git a/gcc/builtins.c b/gcc/builtins.c > index 85affa7..640f1a9 100644 > --- a/gcc/builtins.c > +++ b/gcc/builtins.c > @@ -898,7 +898,8 @@ expand_builtin_setjmp_receiver (rtx receiver_label) > > /* Now put in the code to restore the frame pointer, and argument > pointer, if needed. */ > - if (! targetm.have_nonlocal_goto ()) > + if (! targetm.have_nonlocal_goto () > + && targetm.builtin_setjmp_frame_value () != hard_frame_pointer_rtx) > { > /* First adjust our frame pointer to its actual value. It was > previously set to the start of the virtual area corresponding to > diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h > index e3c52f6..7a21c14 100644 > --- a/gcc/config/aarch64/aarch64.h > +++ b/gcc/config/aarch64/aarch64.h > @@ -474,7 +474,9 @@ extern unsigned aarch64_architecture_version; > #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, R4_REGNUM) > #define EH_RETURN_HANDLER_RTX aarch64_eh_return_handler_rtx () > > -/* Don't use __builtin_setjmp until we've defined it. */ > +/* Don't use __builtin_setjmp until we've defined it. > + CAUTION: This macro is only used during exception unwinding. > + Don't fall for its name. */ > #undef DONT_USE_BUILTIN_SETJMP > #define DONT_USE_BUILTIN_SETJMP 1 > > diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c > index e1fb87f..e7ac0fe 100644 > --- a/gcc/config/aarch64/aarch64.c > +++ b/gcc/config/aarch64/aarch64.c > @@ -12128,6 +12128,13 @@ aarch64_expand_builtin_va_start (tree valist, rtx > nextarg ATTRIBUTE_UNUSED) > expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); > } > > +/* Implement TARGET_BUILTIN_SETJMP_FRAME_VALUE. */ > +static rtx > +aarch64_builtin_setjmp_frame_value (void) > +{ > + return hard_frame_pointer_rtx; > +} > + > /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ > > static tree > @@ -17505,6 +17512,9 @@ aarch64_run_selftests (void) > #undef TARGET_FOLD_BUILTIN > #define TARGET_FOLD_BUILTIN aarch64_fold_builtin > > +#undef TARGET_BUILTIN_SETJMP_FRAME_VALUE > +#define TARGET_BUILTIN_SETJMP_FRAME_VALUE aarch64_builtin_setjmp_frame_value > + > #undef TARGET_FUNCTION_ARG > #define TARGET_FUNCTION_ARG aarch64_function_arg > > diff --git a/gcc/testsuite/gcc.c-torture/execute/pr84521.c > b/gcc/testsuite/gcc.c-torture/execute/pr84521.c > new file mode 100644 > index 0000000..76b10d2 > --- /dev/null > +++ b/gcc/testsuite/gcc.c-torture/execute/pr84521.c > @@ -0,0 +1,49 @@ > +/* { dg-require-effective-target indirect_jumps } */ > + > +#include <setjmp.h> > + > +jmp_buf buf; > + > +int uses_longjmp (void) > +{ > + __builtin_longjmp (buf, 1); > +} > + > +int gl; > +void after_longjmp (void) > +{ > + gl = 5; > +} > + > +int > +test_1 (int n) > +{ > + volatile int *p = alloca (n); > + if (__builtin_setjmp (buf)) > + { > + after_longjmp (); > + } > + else > + { > + uses_longjmp (); > + } > + > + return 0; > +} > + > +int __attribute__ ((optimize ("no-omit-frame-pointer"))) > +test_2 (int n) > +{ > + int i; > + int *ptr = (int *)__builtin_alloca (sizeof (int) * n); > + for (i = 0; i < n; i++) > + ptr[i] = i; > + test_1 (n); > + return 0; > +} > + > +int main (int argc, const char **argv) > +{ > + __builtin_memset (&buf, 0xaf, sizeof (buf)); > + test_2 (100); > +}