Bug 28727 - Wrong code generated (assignment incorrectly optimized out)
Summary: Wrong code generated (assignment incorrectly optimized out)
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: alias, wrong-code
Depends on: 28003
  Show dependency treegraph
Reported: 2006-08-14 18:58 UTC by Marcin 'Qrczak' Kowalczyk
Modified: 2006-08-26 20:46 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:

Test case (498 bytes, text/plain)
2006-08-14 19:00 UTC, Marcin 'Qrczak' Kowalczyk

Note You need to log in before you can comment on or make changes to this bug.
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
        xorl    %eax, %eax

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 ***