Build fails with strict-aliasing violations
I tried to compile with LTO: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.
I got this error:
x86_64-pc-linux-gnu-gcc -I. -I/usr/X11R6/include -I../tcl -I../tclx/src -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -DTK_VERSION=\"2.3\" -DUSE_XPM3 -DIS_LINUX -c -o tk3d.o tk3d.c
tk3d.c: In function ‘Tk_NameOf3DBorder’:
tk3d.c:355:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
355 | return ((BorderKey *) borderPtr->hashPtr->key.words)->colorName;
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [<builtin>: tk3d.o] Error 1
Originally reported downstream: https://bugs.gentoo.org/859223
Full build log: build.log