Skip to content

binaryen does not build with gcc 16 due to -Werror=array-bounds #8950

Description

@whispersofthedawn

When building binaryen with GCC 16 with the default build configuration, the build fails due to the array-bounds warning being promoted to an error.

Reproduction process:

  1. Ensure you have GCC 16. I am using GCC 16.1.0.
  2. Check out binaryen at commit a570236 (latest main at time of writing)
  3. Configure the project with cmake . from the repository root.
  4. Build binaryen with make, and observe the errors that appear.

The errors look like so:

[ 50%] Building CXX object CMakeFiles/binaryen.dir/src/passes/OptimizeForJS.cpp.o
[ 51%] Building CXX object CMakeFiles/binaryen.dir/src/passes/PickLoadSigns.cpp.o
[ 51%] Building CXX object CMakeFiles/binaryen.dir/src/passes/Poppify.cpp.o
[ 51%] Building CXX object CMakeFiles/binaryen.dir/src/passes/PostEmscripten.cpp.o
[ 51%] Building CXX object CMakeFiles/binaryen.dir/src/passes/Precompute.cpp.o
[ 52%] Building CXX object CMakeFiles/binaryen.dir/src/passes/Print.cpp.o
[ 52%] Building CXX object CMakeFiles/binaryen.dir/src/passes/PrintBoundary.cpp.o
In file included from /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/stl_iterator.h:78,
                 from /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/ranges_base.h:39,
                 from /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/ranges_util.h:34,
                 from /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/tuple:46,
                 from /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/functional:71,
                 from /home/whispers/scratchpad/binaryen/src/pass.h:20,
                 from /home/whispers/scratchpad/binaryen/src/ir/module-utils.h:20,
                 from /home/whispers/scratchpad/binaryen/src/passes/PrintBoundary.cpp:54:
In function ‘constexpr void std::destroy_at(_Tp*) [with _Tp = mutex]’,
    inlined from ‘constexpr void std::_Destroy(_Tp*) [with _Tp = mutex]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/stl_construct.h:164:22,
    inlined from ‘static constexpr void std::allocator_traits<std::allocator<void> >::destroy(allocator_type&, _Up*) [with _Up = std::mutex]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/alloc_traits.h:859:17,
    inlined from ‘void std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_M_dispose() [with _Tp = std::mutex; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr_base.h:682:35,
    inlined from ‘void std::_Sp_counted_base<_Lp>::_M_release() [with __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr_base.h:423:18,
    inlined from ‘void std::_Sp_counted_base<_Lp>::_M_release() [with __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr_base.h:392:5,
    inlined from ‘std::__shared_count<_Lp>::~__shared_count() [with __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr_base.h:1136:21,
    inlined from ‘std::__shared_ptr<_Tp, _Lp>::~__shared_ptr() [with _Tp = json::Value; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr_base.h:1610:7,
    inlined from ‘std::shared_ptr<json::Value>::~shared_ptr()’ at /nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/shared_ptr.h:175:11,
    inlined from ‘json::Value::Ref::~Ref()’ at /home/whispers/scratchpad/binaryen/src/support/json.h:63:10,
    inlined from ‘json::Value::Ref wasm::PrintBoundary::getTypes(wasm::Type, bool, size_t)’ at /home/whispers/scratchpad/binaryen/src/passes/PrintBoundary.cpp:129:39:
/nix/store/mcd6qn183lsac6dy6xqm1ijhldixvfq2-gcc-16.1.0/include/c++/16.1.0/bits/stl_construct.h:88:9: error: array subscript ‘std::mutex[0]’ is partly outside array bounds of ‘unsigned char [24]’ [[-Werror=array-bounds=](https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Warray-bounds)]
   88 |         __location->~_Tp();
      |         ^~~~~~~~~~

followed by many more near-identical errors that I've omitted. We've also been encountering this in Nixpkgs while working on upgrading to GCC 16, and there are some full logs available at https://hydra.nixos.org/build/339164126/log (though they are for an older version, binaryen 129).

I've confirmed that this is the only kind of error by setting -DCMAKE_CXX_FLAGS="-Wno-error=array-bounds" and verifying that binaryen successfully builds.

I don't necessarily think this is a binaryen bug. The fact that the location of these warnings is within the the STL seems extremely… wrong. This may be an instance of the GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122197 (in particular, the message about mutex, as there seems to be no mutexes in the affected code paths in binaryen that could be triggering this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122197#c16). However, I wanted to bring this up here in order to seek confirmation that this is indeed not a binaryen bug, and if so, potentially suggest that binaryen suppress this particular warning in the default build configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions