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.
Created attachment 12075 [details] Test case
Most likely related to PR 28003.
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.
*** This bug has been marked as a duplicate of 21920 ***