From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C4AB33856248; Wed, 3 May 2023 15:35:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4AB33856248 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683128106; bh=+kQ+FkdM7eHwhYcKwdmExxQz+JoUhPPF9E2bhn7HE5I=; h=From:To:Subject:Date:From; b=RqbTKTHWMY5XdATvGnAMFDP9EKhZzch8w80bepDAw53ePPMgW8kqfLTCrLNJqIGtp cDMcidgVo4wHwQYRKgoQp8w23rrQeR0aRYIncjFpEMr3+Fjd/583FjSn6ozOipvijR io+yQKCTt2EClSBIajLhKKIWHjA+AZ4v/5pyfUmU= From: "psmith at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109717] New: -Warray-bound error with gnu++20 and fmt library Date: Wed, 03 May 2023 15:35:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: psmith at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109717 Bug ID: 109717 Summary: -Warray-bound error with gnu++20 and fmt library Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: psmith at gnu dot org Target Milestone: --- Created attachment 54983 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54983&action=3Dedit fmt1.i preprocessor output (compressed) I found SO MANY issues related to -Warray-bound, many of them reported with= GCC 11 or so. I can't tell if this is a duplicate or not, although this issue doesn't reproduce for me with GCC 11.3. I have built my own GCC 13.1 from source on x86_64 GNU/Linux (as I've been doing for >10 years) and it works great except for one thing. When I use s= ome parts of the fmt 9.1.0 library, and "-O2 -Werror-builds -std=3Dgnu++20" (re= moving any one of those, or changing to -std=3Dgnu++17, makes the error go away). I try to compile this: #include #include #include void add_info(std::vector& buf) { fmt::format_to(std::back_inserter(buf), "hello {}", "there"); } and I get this output: $ g++-13.1 -I/data/src/build/common/fmt/include -std=3Dgnu++20 -Warray-boun= ds -O2 -c -o /tmp/fmt1.o /tmp/fmt1.cpp In file included from /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/vector:62, from /tmp/fmt1.cpp:1: In static member function 'static constexpr _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _T= p =3D unsigned int; _Up =3D unsigned int; bool _IsMove =3D false]', inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D unsigned int*; _OI =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_algobase.h:506:30, inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D unsigned int*; _OI =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_algobase.h:533:42, inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =3D false; _II =3D unsigned int*; _OI =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_algobase.h:540:31, inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II =3D unsi= gned int*; _OI =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_algobase.h:633:7, inlined from 'static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterat= or, _ForwardIterator) [with _InputIterator =3D unsigned int*; _ForwardIterator = =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_uninitialized.h:147:27, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator =3D unsigned int*; _ForwardIterator =3D unsigned int*]' at /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_uninitialized.h:185:15, inlined from 'constexpr void fmt::v9::basic_memory_buffer::grow(size_t) [with T =3D unsigned int; long unsigned int SIZE = =3D 32; Allocator =3D std::allocator]' at /data/src/build/common/fmt/include/fmt/format.h:925:26, inlined from 'constexpr void fmt::v9::detail::buffer::try_reserve(size_t) [with T =3D unsigned int]' = at /data/src/build/common/fmt/include/fmt/core.h:928:39, inlined from 'constexpr void fmt::v9::detail::buffer::try_reserve(size_t) [with T =3D unsigned int]' = at /data/src/build/common/fmt/include/fmt/core.h:927:24, inlined from 'constexpr void fmt::v9::detail::buffer::try_resize(siz= e_t) [with T =3D unsigned int]' at /data/src/build/common/fmt/include/fmt/core.h:919:16, inlined from 'constexpr void fmt::v9::basic_memory_buffer::resize(size_t) [with T =3D unsigned int; long unsigned int SIZE= =3D 32; Allocator =3D std::allocator]' at /data/src/build/common/fmt/include/fmt/format.h:897:63, inlined from 'constexpr void fmt::v9::detail::bigint::assign(UInt) [with UInt =3D long unsigned int; typename std::enable_if<(std::is_same::value || std::is_same::value), int>::type =3D 0]' at /data/src/build/common/fmt/include/fmt/format.h:2792:19, inlined from 'constexpr void fmt::v9::detail::bigint::operator=3D(Int) = [with Int =3D int]' at /data/src/build/common/fmt/include/fmt/format.h:2813:11, inlined from 'constexpr void fmt::v9::detail::bigint::assign_pow10(int)= ' at /data/src/build/common/fmt/include/fmt/format.h:2886:32: /data/src/build/x86_64-linux/cc/unknown/x86_64-unknown-linux-gnu/include/c+= +/13.1.0/bits/stl_algobase.h:437:30: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming offset 4 is out of the bounds [0, 4] [-Warray-bounds=3D] 437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's very strange that it says "offset 4" is out of bounds for [0, 4] but m= aybe I just don't understand the error. The code in fmt/format.h line 2886 is: // Assigns pow(10, exp) to this bigint. FMT_CONSTEXPR20 void assign_pow10(int exp) { FMT_ASSERT(exp >=3D 0, ""); if (exp =3D=3D 0) return *this =3D 1; //<=3D=3D line 2886 If I don't use the fmt::format_to() function (just normal fmt::print etc.) = then it works fine. Also I should point out that for some reason I can't reproduce this with godbolt using GCC 13.1 and fmt 9.1.0. I also can't reproduce it with my previous build, GCC 11.3 (but all else the same). I'll add the postprocessed output (where I still see the above error) as an attachment.=