noreturn attribute on a function causes sibling calling optimization not to be able to be done, so it causes more code to be executed then needed.
GNU C version 3.4 20030516 and GNU C version 3.4 20030517
powerpc-apple-darwin6.6 and i686-pc-linux-gnu
cat >tt.c <<EOF
void temp2() __attribute__((__noreturn__));
gcc -O3 -fomit-frame-pointer tt.c -S
look at the asm and see that temp4 has the optimization but temp1 does not.
if the attrubute is on a function, act like it is a return statement also, so that the sibiling call optimization will always work with that one.
Working as designed.
(1) It often takes more insns to pop the stack frame than to make the call.
(2) You get a proper backtrace from abort.
*** Bug 33083 has been marked as a duplicate of this bug. ***
Some comments from the outside:
(1) It should be possible to exchange the emmited call into a jmp, without adding the function epilog.
(2) A proper backtrace is not generated on optimized sibling functions.
(3) http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00180.html explains, that it is hard to implement
(4) abort produce a proper backtrace, if it is not a noreturn function
(5) this optimization could be configurable by something like -foptimize-noreturns
*** Bug 34589 has been marked as a duplicate of this bug. ***
*** Bug 56165 has been marked as a duplicate of this bug. ***
In this case, perhaps sibling call optimization is the wrong thing here. The caller of a noreturn function shouldn't pop the stack, but it also shouldn't save registers (and, if it doesn't need to save registers, it shouldn't create a stack frame in the first place).
*** Bug 58152 has been marked as a duplicate of this bug. ***
*** Bug 67327 has been marked as a duplicate of this bug. ***
(In reply to Richard Henderson from comment #2)
> Working as designed.
> (1) It often takes more insns to pop the stack frame than to make the call.
> (2) You get a proper backtrace from abort.
> (3) http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00180.html
Glibc has been using
movl 12(%esp), %eax
cmpl %eax, 16(%esp)
since 2004. #1 and #2 shouldn't be the reason not to optimize. I
/* Due to
noreturn attribute disable tail call optimization. Removes noreturn
attribute to enable tail call optimization. */
extern void *chk_fail (void) __asm__ ("__chk_fail") attribute_hidden;
to work around this.
*** Bug 68677 has been marked as a duplicate of this bug. ***