Bug 10837 - noreturn attribute causes no sibling calling optimization
Summary: noreturn attribute causes no sibling calling optimization
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 33083 34589 56165 58152 67327 68677 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-17 17:16 UTC by Andrew Pinski
Modified: 2015-12-03 17:54 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2003-05-17 17:16:00 UTC
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.

Release:
GNU C version 3.4 20030516 and GNU C version 3.4 20030517

Environment:
powerpc-apple-darwin6.6 and i686-pc-linux-gnu

How-To-Repeat:
cat >tt.c <<EOF
void temp()
{
                abort();
}

void temp2() __attribute__((__noreturn__));
void temp1()
{
        temp2();
}

void temp3();

void temp4()
{
        temp3();
}
EOF
gcc -O3 -fomit-frame-pointer tt.c -S
look at the asm and see that temp4 has the optimization but temp1 does not.
Comment 1 Andrew Pinski 2003-05-17 17:16:00 UTC
Fix:
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.
Comment 2 Richard Henderson 2003-05-23 15:28:22 UTC
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
Comment 3 Andrew Pinski 2007-08-16 10:38:55 UTC
*** Bug 33083 has been marked as a duplicate of this bug. ***
Comment 4 Bernhard Kauer 2007-08-28 19:07:18 UTC
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
Comment 5 Bernhard Kauer 2007-08-28 19:27:38 UTC
(4) abort produce a proper backtrace, if it is not a noreturn function
(5) this optimization could be configurable by something like -foptimize-noreturns
Comment 6 Andrew Pinski 2007-12-26 09:36:14 UTC
*** Bug 34589 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2013-01-31 21:46:42 UTC
*** Bug 56165 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2013-02-03 02:18:59 UTC
*** Bug 56165 has been marked as a duplicate of this bug. ***
Comment 9 Andy Lutomirski 2013-08-10 00:16:54 UTC
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).
Comment 10 Andrew Pinski 2013-08-14 15:38:33 UTC
*** Bug 58152 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2015-08-23 13:41:10 UTC
*** Bug 67327 has been marked as a duplicate of this bug. ***
Comment 12 H.J. Lu 2015-08-25 11:25:59 UTC
(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

ENTRY (__memmove_chk)
	movl	12(%esp), %eax
	cmpl	%eax, 16(%esp)
	jb	__chk_fail
	jmp	memmove
END (__memmove_chk)

since 2004. #1 and #2 shouldn't be the reason not to optimize.  I
am using:

/* Due to
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10837
   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.
Comment 13 Andrew Pinski 2015-12-03 17:54:56 UTC
*** Bug 68677 has been marked as a duplicate of this bug. ***