Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with strict-aliasing violations #110

Open
eli-schwartz opened this issue Mar 12, 2024 · 0 comments
Open

Build fails with strict-aliasing violations #110

eli-schwartz opened this issue Mar 12, 2024 · 0 comments

Comments

@eli-schwartz
Copy link

eli-schwartz commented Mar 12, 2024

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:

/bin/sh ../libtool  --tag=CC   --mode=compile x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I../include/IL  -I ./../src-IL/include -I ./../include  -std=gnu99 -fgnu89-inline -msse -msse2 -msse3  -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 -c -o libIL_la-il_convbuff.lo `test -f './../src-IL/src/il_convbuff.c' || echo './'`./../src-IL/src/il_convbuff.c
libtool: compile:  x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I../include/IL -I ./../src-IL/include -I ./../include -std=gnu99 -fgnu89-inline -msse -msse2 -msse3 -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 -c ./../src-IL/src/il_convbuff.c  -fPIC -DPIC -o .libs/libIL_la-il_convbuff.o
./../src-IL/src/il_convbuff.c: In function 'iSwitchTypes':
./../src-IL/src/il_convbuff.c:2029:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2029 |                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
      |                                                          ~^~~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2081:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2081 |                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
      |                                                          ~^~~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2134:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2134 |                                                         *((ILuint*)&tempFloat) = ilHalfToFloat(((ILushort*)Buffer)[i]);
      |                                                          ~^~~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2240:50: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2240 |                                                 *(ILuint*)&tempFloat = ilHalfToFloat(((ILushort*)Buffer)[i]);
      |                                                  ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2259:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2259 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2265:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2265 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2271:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2271 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2277:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2277 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2283:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2283 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2289:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2289 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2295:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2295 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
./../src-IL/src/il_convbuff.c:2301:84: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
 2301 |                                         *((ILushort*)&HalfPtr[i]) = ilFloatToHalf(*(ILuint*)&tempFloat);
      |                                                                                    ^~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [Makefile:1012: libIL_la-il_convbuff.lo] Error 1

Downstream report: https://bugs.gentoo.org/859835
Full build log: build.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant