When a noreturn function is called, the compiler should emit a "jmp"
instruction rather than "call", because the called function will not return.
Saving callee-save registers in the function prologue also seems unnecessary
since there won't be an epilogue to restore them.

The following example uses 'noinline' to prevent gcc from inlining these
trivial functions.

#define NOINLINE __attribute__((noinline))
#define NORETURN __attribute__((noreturn))

NORETURN NOINLINE
static void f1()
{
    for (;;);
}

NORETURN NOINLINE
static void f2()
{
    f1();
}

int main()
{
    f2();
    return 0;
}

This results in the following code:

08048228 <f1>:
 8048228:       55                      push   %ebp
 8048229:       89 e5                   mov    %esp,%ebp
 804822b:       eb fe                   jmp    804822b <f1+0x3>

0804822d <f2>:
 804822d:       55                      push   %ebp
 804822e:       89 e5                   mov    %esp,%ebp
 8048230:       e8 f3 ff ff ff          call   8048228 <f1>    <= this should
be jmp


-- 
           Summary: noreturn function should be invoked via JMP
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: us15 at os dot inf dot tu-dresden dot de
 GCC build triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33083

Reply via email to