Hello! Naked functions should not sibcall, since in naked functions epilogue point (placed just above sibcal insn) is unreachable and marked with a trap insn.
2017-08-01 Uros Bizjak <ubiz...@gmail.com> PR target/81639 * config/i386/i386.c (ix86_funciton_naked): New prototype. (ix86_function_ok_for_sibcall): Return false for naked functions. testsuite/ChangeLog: 2017-08-01 Uros Bizjak <ubiz...@gmail.com> PR target/81639 * gcc.target/i386/pr81639.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline. Uros.
Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 250758) +++ config/i386/i386.c (working copy) @@ -94,6 +94,7 @@ static rtx legitimize_pe_coff_extern_decl (rtx, bo static rtx legitimize_pe_coff_symbol (rtx, bool); static void ix86_print_operand_address_as (FILE *, rtx, addr_space_t, bool); static bool ix86_save_reg (unsigned int, bool, bool); +static bool ix86_function_naked (const_tree); #ifndef CHECK_STACK_LIMIT #define CHECK_STACK_LIMIT (-1) @@ -7929,6 +7930,9 @@ ix86_function_ok_for_sibcall (tree decl, tree exp) rtx a, b; bool bind_global = decl && !targetm.binds_local_p (decl); + if (ix86_function_naked (current_function_decl)) + return false; + /* Sibling call isn't OK if there are no caller-saved registers since all registers must be preserved before return. */ if (cfun->machine->no_caller_saved_registers) Index: testsuite/gcc.target/i386/pr81639.c =================================================================== --- testsuite/gcc.target/i386/pr81639.c (nonexistent) +++ testsuite/gcc.target/i386/pr81639.c (working copy) @@ -0,0 +1,12 @@ +/* PR target/81639 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void b (void); + +void +__attribute__ ((naked)) +a (void) +{ + b (); +}