Closed
Description
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:
FAILED: rocclr/CMakeFiles/rocclr.dir/platform/memory.cpp.o
/usr/bin/x86_64-pc-linux-gnu-g++ -DATI_OS_LINUX -DCL_TARGET_OPENCL_VERSION=220 -DCL_USE_DEPRECATED_OPENCL_1_0_APIS -DCL_USE_DEPRECATED_OPENCL_1_1_APIS -DCL_USE_DEPRECATED_OPENCL_1_2_APIS -DCL_USE_DEPRECATED_OPENCL_2_0_APIS -DCOMGR_DYN_DLL -DHAVE_CL2_HPP -DHIP_MAJOR_VERSION=5 -DHIP_MINOR_VERSION=7 -DLITTLEENDIAN_CPU -DOPENCL_C_MAJOR=2 -DOPENCL_C_MINOR=0 -DOPENCL_MAJOR=2 -DOPENCL_MINOR=1 -DROCCLR_SUPPORT_NUMA_POLICY -DUSE_COMGR_LIBRARY -DWITH_HSA_DEVICE -DWITH_LIGHTNING_COMPILER -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/compiler/lib -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/compiler/lib/include -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/compiler/lib/backends/common -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/device -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/elf -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/include -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL/.. -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL/../.. -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL/../../.. -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL/../../../.. -I/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/opencl/khronos/headers/opencl2.2/CL/../../../../amdocl -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 -std=c++17 -fPIC -MD -MT rocclr/CMakeFiles/rocclr.dir/platform/memory.cpp.o -MF rocclr/CMakeFiles/rocclr.dir/platform/memory.cpp.o.d -o rocclr/CMakeFiles/rocclr.dir/platform/memory.cpp.o -c /var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp: In function ‘int amd::round_to_even(float)’:
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1285:19: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1285 | if (fabsf(v) < *reinterpret_cast<const float*>(&magic[0])) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1286:23: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1286 | float magicVal = *reinterpret_cast<const float*>(&magic[v < 0.0f]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp: In function ‘uint16_t amd::float2half_rtz(float)’:
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1311:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1311 | if (x >= *reinterpret_cast<float*>(&values[0])) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1312:15: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1312 | if (x == *reinterpret_cast<float*>(&values[4])) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1319:12: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1319 | if (x < *reinterpret_cast<float*>(&values[1])) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1324:12: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1324 | if (x < *reinterpret_cast<float*>(&values[2])) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/dev-util/hip-5.7.1-r2/work/clr-rocm-5.7.1/rocclr/platform/memory.cpp:1325:11: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
1325 | x *= *reinterpret_cast<float*>(&values[3]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
ninja: build stopped: cannot make progress due to previous errors.
Downstream report: https://bugs.gentoo.org/858383
Full build log: build.log