From: Uros Bizjak Date: Mon, 31 Jul 2017 13:11:59 +0000 (+0200) Subject: re PR target/25967 (Add attribute naked for x86) X-Git-Tag: upstream/12.2.0~37873 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a97cf8f9a381ee26b80c5ccd874deeed3218e79a;p=platform%2Fupstream%2Fgcc.git re PR target/25967 (Add attribute naked for x86) PR target/25967 * config/i386/i386.c (ix86_allocate_stack_slots_for_args): New function. (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define. testsuite/ChangeLog: PR target/25967 * gcc.target/i386/naked-3.c (dg-options): Use -O0. (naked): Add attribute regparm(1) for x86_32 targets. Add integer argument. Remove global "data" variable. (main): Pass integer argument to naked function. * gcc.target/i386/naked-4.c: New test. From-SVN: r250742 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 27e4af1..27130e8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-07-31 Uros Bizjak + + PR target/25967 + * config/i386/i386.c (ix86_allocate_stack_slots_for_args): + New function. + (TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS): Define. + 2017-07-31 Andreas Krebbel * config.gcc: Add z14. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 9a35c99..29a6dc3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -31676,6 +31676,13 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) } static bool +ix86_allocate_stack_slots_for_args (void) +{ + /* Naked functions should not allocate stack slots for arguments. */ + return !ix86_function_naked (current_function_decl); +} + +static bool ix86_warn_func_return (tree decl) { /* Naked functions are implemented entirely in assembly, including the @@ -52727,6 +52734,8 @@ ix86_run_selftests (void) #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs #undef TARGET_MUST_PASS_IN_STACK #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack +#undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS +#define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS ix86_allocate_stack_slots_for_args #undef TARGET_FUNCTION_ARG_ADVANCE #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance #undef TARGET_FUNCTION_ARG diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7243fdf..7edb3a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-07-31 Uros Bizjak + + PR target/25967 + * gcc.target/i386/naked-3.c (dg-options): Use -O0. + (naked): Add attribute regparm(1) for x86_32 targets. + Add integer argument. Remove global "data" variable. + (main): Pass integer argument to naked function. + * gcc.target/i386/naked-4.c: New test. + 2017-07-31 Jan Hubicka Martin Liska diff --git a/gcc/testsuite/gcc.target/i386/naked-3.c b/gcc/testsuite/gcc.target/i386/naked-3.c index 845300d..b3a17f6 100644 --- a/gcc/testsuite/gcc.target/i386/naked-3.c +++ b/gcc/testsuite/gcc.target/i386/naked-3.c @@ -1,17 +1,18 @@ /* { dg-do run { target *-*-linux* *-*-gnu* } } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O0" } */ #include #include #include -int data; - /* Verify that naked function traps at the end. */ void __attribute__((naked, noinline, noclone)) -naked (void) +#ifdef __i386__ +__attribute__((regparm(1))) +#endif +naked (int data) { if (data == 0x12345678) return; @@ -32,8 +33,7 @@ int main () s.sa_flags = 0; sigaction (SIGILL, &s, NULL); - data = 0x12345678; - naked (); + naked (0x12345678); abort (); } diff --git a/gcc/testsuite/gcc.target/i386/naked-4.c b/gcc/testsuite/gcc.target/i386/naked-4.c new file mode 100644 index 0000000..07b3242 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/naked-4.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ +/* { dg-additional-options "-mregparm=3" { target ia32 } } */ + +/* Verify that __attribute__((naked)) produces a naked function + that does not allocate stack slots for args. */ +extern void bar (int); + +int +__attribute__((naked)) +foo (int a, int b, int c) +{ + bar (c); + asm volatile ("ret" :: "a" (b)); +} + +/* { dg-final { scan-assembler-not "%\[re\]bp" } } */