http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56576
Bug #: 56576 Summary: wrong code for aliased union at -O3 Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: dhaze...@yahoo.com The following code behaves differently at -O3 than at -O2 or below on 4.7 and mainline on x86_64-linux. At -O3 it returns 1, whereas at -O2 and below it returns 0, for both -m32 and -m64 targets. It behaves as expected on gcc 4.6 at all optimization levels (returns 0). $ gcc-trunk --version gcc-trunk (GCC) 4.8.0 20130308 (experimental) [trunk revision 196555] $ gcc-trunk -O2 trans-reduced.c $ ./a.out $ echo $? 0 $ gcc-trunk -O3 trans-reduced.c $ ./a.out $ echo $? 1 $ gcc-4.6 -O3 trans-reduced.c $ ./a.out $ echo $? 0 $ cat trans-reduced.c /* gcc-4.7/gcc-trunk -O3 -m32/-m64 */ union { int f0; int f1; long f2; } a, b; int c, h; int *d, *e = &a.f0; long *f = &b.f2; int **g = &d; void fn1 () { c = 0; for (; c <= 3; c++) { int *i = &b.f1; *f = 1; *i = 0; *g = 0; h = *e; } } int main () { fn1 (); return b.f0; }