Skip to content

Build tests/YGPersistenceTest.cpp fails with array-bounds error on GCC 16 (-O2 / -O3) due to -Werror #1934

Description

@peeweep

Gentoo Linux use -O2 as default optimization option, there is a array-bounds error when use g++ -O2 or -O3

Step to reproduced:

export CXXFLAGS="-O2"
export CXX="g++"
cmake -B build -DBUILD_FUZZ_TESTS=OFF
cmake --build build -j1

or

export CXX="g++"
./unit_tests Release # CMAKE_BUILD_TYPE=Release will use -O3

array-bounds error log:

[ 27%] Building CXX object tests/CMakeFiles/yogatests.dir/YGPersistenceTest.cpp.o
cd /tmp/yoga/build/tests && /usr/bin/g++  -I/tmp/yoga/yoga/.. -isystem /tmp/yoga/build/_deps/googletest-src/googletest/include -isystem /tmp/yoga/build/_deps/googletest-src/googletest -O2 -fPIE -fvisibility=hidden -fno-omit-frame-pointer -fexceptions -Wall -Werror -frtti -MD -MT tests/CMakeFiles/yogatests.dir/YGPersistenceTest.cpp.o -MF CMakeFiles/yogatests.dir/YGPersistenceTest.cpp.o.d -o CMakeFiles/yogatests.dir/YGPersistenceTest.cpp.o -c /tmp/yoga/tests/YGPersistenceTest.cpp
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_tempbuf.h:61,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/memory:68,
                 from /tmp/yoga/build/_deps/googletest-src/googletest/include/gtest/gtest.h:54,
                 from /tmp/yoga/tests/YGPersistenceTest.cpp:8:
In function ‘constexpr _Tp* std::construct_at(_Tp*, _Args&& ...) [with _Tp = facebook::yoga::Node*; _Args = {facebook::yoga::Node*}]’,
    inlined from ‘static constexpr void std::allocator_traits<std::allocator<_Up> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = facebook::yoga::Node*; _Args = {facebook::yoga::Node*}; _Tp = facebook::yoga::Node*]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/alloc_traits.h:716:21,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::_M_insert_aux(iterator, _Arg&&) [with _Arg = facebook::yoga::Node*; _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/vector.tcc:434:31,
    inlined from ‘constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::_M_insert_rval(const_iterator, value_type&&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/vector.tcc:381:17,
    inlined from ‘constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:1519:30,
    inlined from ‘virtual void YogaTest_mixed_shared_and_owned_children_Test::TestBody()’ at /tmp/yoga/tests/YGPersistenceTest.cpp:278:18:
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_construct.h:110:16: error: array subscript -1 is outside array bounds of ‘facebook::yoga::Node* [1152921504606846975]’ [-Werror=array-bounds=]
  110 |         return ::new(__loc) _Tp(std::forward<_Args>(__args)...);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/allocator.h:46,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/memory:67:
In member function ‘constexpr _Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = facebook::yoga::Node*]’,
    inlined from ‘constexpr _Tp* std::allocator< <template-parameter-1-1> >::allocate(std::size_t) [with _Tp = facebook::yoga::Node*]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/allocator.h:206:40,
    inlined from ‘static constexpr _Tp* std::allocator_traits<std::allocator<_Up> >::allocate(allocator_type&, size_type) [with _Tp = facebook::yoga::Node*]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/alloc_traits.h:638:28,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:389:33,
    inlined from ‘constexpr void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:407:44,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:341:26,
    inlined from ‘constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]’ at /usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:623:61,
    inlined from ‘virtual void YogaTest_mixed_shared_and_owned_children_Test::TestBody()’ at /tmp/yoga/tests/YGPersistenceTest.cpp:277:64:
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/new_allocator.h:162:75: note: at offset -8 into object of size [0, 9223372036854775800] allocated by ‘operator new’
  162 |           return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp)));
      |                                                                           ^
cc1plus: all warnings being treated as errors
gmake[2]: *** [tests/CMakeFiles/yogatests.dir/build.make:446: tests/CMakeFiles/yogatests.dir/YGPersistenceTest.cpp.o] Error 1
gmake[2]: Leaving directory '/tmp/yoga/build'
gmake[1]: *** [CMakeFiles/Makefile2:258: tests/CMakeFiles/yogatests.dir/all] Error 2
gmake[1]: Leaving directory '/tmp/yoga/build'
gmake: *** [Makefile:139: all] Error 2

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