This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]