https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82224
Alexander Cherepanov <ch3root at openwall dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ch3root at openwall dot com --- Comment #6 from Alexander Cherepanov <ch3root at openwall dot com> --- Here are simplified testcases. With a union (C and C++): ---------------------------------------------------------------------- #include <stdio.h> union u { long x; long long y; }; static long test(long *px, long long *py, union u *pu) { pu->x = 0; // make .x active member (for C++) *px = 0; // access .x via pointer pu->y = pu->x; // switch active member to .y (for C++) *py = 1; // access .y via pointer pu->x = pu->y; // switch active member back to .x return *px; // access .x via pointer } int main(void) { union u u; printf("%ld\n", test(&u.x, &u.y, &u)); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out 1 $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 0 ---------------------------------------------------------------------- And with allocated memory (C; add placement new's for C++): ---------------------------------------------------------------------- #include <stdlib.h> #include <string.h> #include <stdio.h> static long test(long *px, long long *py, void *pu) { *px = 0; *py = 1; // change effective type from long long to long long tmp; memcpy(&tmp, pu, sizeof(tmp)); memcpy(pu, &tmp, sizeof(tmp)); return *px; } int main(void) { void *p = malloc(10); printf("%ld\n", test(p, p, p)); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out 1 $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out 0 ---------------------------------------------------------------------- gcc version: gcc (GCC) 8.0.0 20171023 (experimental)