[Bug rtl-optimization/51353] New: GCC incorrectly optimizes away assignment to return address

nkeynes at deadcoderemoval dot net gcc-bugzilla@gcc.gnu.org
Wed Nov 30 09:14:00 GMT 2011


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: unassigned@gcc.gnu.org
        ReportedBy: nkeynes@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.



More information about the Gcc-bugs mailing list