Bug 28727

Summary: Wrong code generated (assignment incorrectly optimized out)
Product: gcc Reporter: Marcin 'Qrczak' Kowalczyk <qrczak>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: cdfrey, chiabaut, fang, gcc-bugs, pinskia, qrczak, sorenj, takahisa.yokota
Priority: P3 Keywords: alias, wrong-code
Version: 4.2.0   
Target Milestone: ---   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed:
Bug Depends on: 28003    
Bug Blocks:    
Attachments: Test case

Description Marcin 'Qrczak' Kowalczyk 2006-08-14 18:58:48 UTC
The attached module, when compiled with -O2, has wrong code generated for the last set_global_field call. The assembly shows:

        leal    4(%edx), %eax
        cmpl    marked_limit, %eax
        movl    BadArguments, %ecx
        movl    $record_12420+4, (%edx)
        movl    %eax, marked_top
        jbe     .L28
        movl    %ecx, record_12420+4
        call    gc
.L28:
        leave
        xorl    %eax, %eax
        ret

while the assignment of BadArguments (from %ecx) to record_12420+4 should be performed unconditionally, as can be easily deduced from the source.

This is gcc-4.2.0-0.20060806r115974. The bug doesn't manifest without -O2 or when the number of set_global_field calls is reduced.
Comment 1 Marcin 'Qrczak' Kowalczyk 2006-08-14 19:00:04 UTC
Created attachment 12075 [details]
Test case
Comment 2 Andrew Pinski 2006-08-14 19:10:56 UTC
Most likely related to PR 28003.
Comment 3 Marcin 'Qrczak' Kowalczyk 2006-08-26 19:15:40 UTC
The problem seems to be caused by illegal type punning. Rewriting the code to avoid pointer casts cures the bug, and -fno-strict-aliasing cures it too, so gcc is probably correct.

Thanks to Michael Veksler for pointing this out.
Comment 4 Andrew Pinski 2006-08-26 20:46:25 UTC

*** This bug has been marked as a duplicate of 21920 ***