https://gcc.gnu.org/bugzilla/show_bug.cgi?id=73434
Bug ID: 73434 Summary: [6 Regression] Wrong code with casting, branches and aliasing Product: gcc Version: 6.1.1 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gcc at thecybershadow dot net Target Milestone: --- /////////////////// test.c ////////////////// #include <assert.h> typedef struct { unsigned char x; } A; typedef struct { unsigned char x; } B; int idx = 0; A objs[1] = {{0}}; int main() { B *b = (B*)&objs[idx]; b->x++; if (b->x) // Always true b->x = 0; // Always executed assert(!b->x); // b->x should always be 0 return 0; } ///////////////////////////////////////////// Works fine with: gcc -O1 gcc -O2 -fno-strict-aliasing Assert fails with: gcc -O2 gcc -O1 -fstrict-aliasing Even though -fno-strict-aliasing makes a difference, the variable is accessed through a single pointer. Reproducible with: - 6.1.0 on i686-w64-mingw32 from msys2 - 6.1.1 on x86_64-pc-linux-gnu from Arch Linux - 6.1.1 on arm-linux-gnueabihf from ppa:ubuntu-toolchain-r/test Not reproducible with 5.4.0.