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

             Bug #: 51353
           Summary: GCC incorrectly optimizes away assignment to return
                    address
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: nkey...@deadcoderemoval.net


In the following code, GCC with -O completely removes the if block and
assignment:

int foo( int arg, void *exc )
{
    if( arg < 2 ) {
        *(((void **)__builtin_frame_address(0))+1) = exc;
    }
    return 0;
}

Producing (for i386):
.globl _foo
_foo:
    pushl    %ebp
    movl    %esp, %ebp
    movl    $0, %eax
    popl    %ebp
    ret

The relative merits and portability of the code aside, it doesn't seem correct
to completely remove the assignment. 

The code was compiled correctly with gcc 4.2.4, and fails with 4.4.6, 4.5.3,
and 4.6.1. The generated code is also correct with all optimizations off when
compiled with any of these versions.

Reply via email to