Dobiasd / FunctionalPlus

Functional Programming Library for C++. Write concise and readable C++ code.
http://www.editgym.com/fplus-api-search/
Boost Software License 1.0
2.07k stars 168 forks source link

Add GCC 13 to tests #280

Closed Dobiasd closed 10 months ago

Dobiasd commented 10 months ago

Interesting, GCC 13 fails:

In file included from /usr/local/include/c++/13.2.0/bits/specfun.h:43,
                 from /usr/local/include/c++/13.2.0/cmath:3699,
                 from /usr/local/include/doctest/doctest.h:3108,
                 from /__w/FunctionalPlus/FunctionalPlus/test/numeric_test.cpp:7:
In static member function 'static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const double; _Up = double; bool _IsMove = false]',
    inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const double*; _OI = double*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:506:30,
    inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const double*; _OI = double*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:533:42,
    inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const double*, vector<double> >; _OI = double*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:540:31,
    inlined from '_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const double*, vector<double> >; _OI = double*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:633:7,
    inlined from 'static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _ForwardIterator = double*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:147:27,
    inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, vector<double> >; _ForwardIterator = double*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:1[85](https://github.com/Dobiasd/FunctionalPlus/actions/runs/6181346493/job/16779161250?pr=280#step:6:86):15,
    inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, vector<double> >; _ForwardIterator = double*; _Tp = double]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:373:37,
    inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = double; _Alloc = std::allocator<double>]' at /usr/local/include/c++/13.2.0/bits/stl_vector.h:603:31,
    inlined from 'Container fplus::winsorize(double, const Container&) [with Container = std::vector<double>]' at /__w/FunctionalPlus/FunctionalPlus/include/fplus/split.hpp:718:16:
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:437:30: error: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming offset 8 is out of the bounds [0, 8] [-Werror=array-bounds=]
  437 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

One can reproduce it locally in Docker:

docker run --rm -it --name some-gcc gcc:13

Funnily, replacing

cmake -S test -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 4

with

cmake -S test -B build
cmake --build build -j 4

makes it work:

apt update
apt install -y cmake

git clone --depth=1 --branch=v2.4.9 https://github.com/doctest/doctest
cd doctest && mkdir -p build && cd build
cmake .. -DDOCTEST_WITH_TESTS=OFF -DDOCTEST_WITH_MAIN_IN_STATIC_LIB=OFF
cmake --build . --config Release --target install
cd ..
cd ..

# works
mkdir normal
cd normal
git clone https://github.com/Dobiasd/FunctionalPlus
cd FunctionalPlus
cmake -S test -B build
cmake --build build -j 4
# cd build
# ctest -C Release -j $ --output-on-failure
# cd ..
cd ..
cd ..

# errors
mkdir release
cd release
git clone https://github.com/Dobiasd/FunctionalPlus
cd FunctionalPlus
cmake -S test -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 4
# cd build
# ctest -C Release -j 4 --output-on-failure
# cd ..
cd ..
cd ..
offa commented 10 months ago

Release builds with optimizations and some additional bounds checks.

Dobiasd commented 10 months ago

I continued to inline and chop off things in numeric_test.cpp to arrive at this minimal example:

#include <vector>

std::vector<int> foo(const std::vector<int>& a)
{
    if (a.size() < 2)
    {
        return a;
    }
    return a;
}

int main()
{
    foo(std::vector<int>({1}));
}

The error still happens:

/usr/local/include/c++/13.2.0/bits/stl_algobase.h:437:30: error: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming offset 4 is out of the bounds [0, 4] [-Werror=array-bounds=]

So I guess it's a false positive.

Dobiasd commented 10 months ago

This clumsy workaround fixes it: https://github.com/Dobiasd/FunctionalPlus/pull/280/commits/726e70866983b8c55c7240ed20e5c2d2cd61fc14

Dobiasd commented 10 months ago

It only happens with -O3, that's why we only see it with CMAKE_BUILD_TYPE=Release.

I've opened a bug ticket here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111415