DentonW / DevIL

Developer's Image Library (DevIL) is a cross-platform image library utilizing a simple syntax to load, save, convert, manipulate, filter, and display a variety of images with ease. It is highly portable and has been ported to several platforms.
http://openil.sourceforge.net/
GNU Lesser General Public License v2.1
446 stars 137 forks source link

Build fails with strict-aliasing violations #110

Open eli-schwartz opened 8 months ago

eli-schwartz commented 8 months ago

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