https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71452
Bug ID: 71452 Summary: Wrong optimization of stores to _Bool via char* Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ch3root at openwall dot com Target Milestone: --- Source code: ---------------------------------------------------------------------- #include <stdio.h> int main() { _Bool b; *(char *)&b = 123; printf("%d\n", *(char *)&b); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out 123 $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 1 ---------------------------------------------------------------------- gcc version: gcc (GCC) 7.0.0 20160604 (experimental) This is somewhat counterintuitive behavior and it's a bug according to https://gcc.gnu.org/ml/gcc/2016-06/msg00046.html . According to https://gcc.godbolt.org/ such optimization is observed with gcc 4.6.4 but not in gcc 4.5.3.