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] Tests fail with strict-aliasing violations #1784

Open
eli-schwartz opened this issue Apr 3, 2024 · 0 comments
Open

[BUILD] Tests fail with strict-aliasing violations #1784

eli-schwartz opened this issue Apr 3, 2024 · 0 comments
Labels

Comments

@eli-schwartz
Copy link

I tried to build with the following *FLAGS to optimize the build: -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: nanovdb/nanovdb/unittest/CMakeFiles/nanovdb_test_nanovdb.dir/TestNanoVDB.cc.o 
/usr/bin/ccache /usr/bin/x86_64-pc-linux-gnu-g++ -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DGTEST_LINKED_AS_SHARED_LIBRARY=1 -DNANOVDB_USE_BLOSC -DNANOVDB_USE_INTRINSICS -DNANOVDB_USE_OPENVDB -DNANOVDB_USE_TBB -DNANOVDB_USE_ZIP -DOPENVDB_DLL -DOPENVDB_USE_AVX -DOPENVDB_USE_DELAYED_LOADING -DOPENVDB_USE_LOG4CPLUS -DOPENVDB_USE_SSE42 -I/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/.. -I/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/openvdb/openvdb/.. -I/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0_build-install/openvdb/openvdb -I/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0_build-install/openvdb/openvdb/openvdb -isystem /usr/include/Imath  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=c++17 -fdiagnostics-color=always -mavx -msse4.2 -Wno-invalid-offsetof -MD -MT nanovdb/nanovdb/unittest/CMakeFiles/nanovdb_test_nanovdb.dir/TestNanoVDB.cc.o -MF nanovdb/nanovdb/unittest/CMakeFiles/nanovdb_test_nanovdb.dir/TestNanoVDB.cc.o.d -o nanovdb/nanovdb/unittest/CMakeFiles/nanovdb_test_nanovdb.dir/TestNanoVDB.cc.o -c /var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/unittest/TestNanoVDB.cc
In file included from /var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/unittest/TestNanoVDB.cc:40:
/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/../nanovdb/PNanoVDB.h: In function ‘pnanovdb_uint32_t pnanovdb_float_as_uint32(float)’:
/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/../nanovdb/PNanoVDB.h:347:86: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  347 | PNANOVDB_FORCE_INLINE pnanovdb_uint32_t pnanovdb_float_as_uint32(float v) { return *((pnanovdb_uint32_t*)(&v)); }
      |                                                                                     ~^~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/../nanovdb/PNanoVDB.h: In function ‘pnanovdb_uint64_t pnanovdb_double_as_uint64(double)’:
/var/tmp/portage/media-gfx/openvdb-11.0.0/work/openvdb-11.0.0/nanovdb/nanovdb/../nanovdb/PNanoVDB.h:349:88: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  349 | PNANOVDB_FORCE_INLINE pnanovdb_uint64_t pnanovdb_double_as_uint64(double v) { return *((pnanovdb_uint64_t*)(&v)); }
      |                                                                                       ~^~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
ninja: build stopped: subcommand failed.

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

It should be noted that this error only occurs when building the testsuite.

@Idclip Idclip added the nanovdb label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants