public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "psmith at gnu dot org" <gcc-bugzilla@gcc.gnu.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 [thread overview] Message-ID: <bug-109717-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109717 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=54983&action=edit 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 some parts of the fmt 9.1.0 library, and "-O2 -Werror-builds -std=gnu++20" (removing any one of those, or changing to -std=gnu++17, makes the error go away). I try to compile this: #include <vector> #include <iterator> #include <fmt/format.h> void add_info(std::vector<char>& 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=gnu++20 -Warray-bounds -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 _Tp = unsigned int; _Up = unsigned int; bool _IsMove = false]', inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = unsigned int*; _OI = 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 bool _IsMove = false; _II = unsigned int*; _OI = 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 = false; _II = unsigned int*; _OI = 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 = unsigned int*; _OI = 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<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = unsigned int*; _ForwardIterator = 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 = unsigned int*; _ForwardIterator = 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<T, SIZE, Allocator>::grow(size_t) [with T = unsigned int; long unsigned int SIZE = 32; Allocator = std::allocator<unsigned int>]' at /data/src/build/common/fmt/include/fmt/format.h:925:26, inlined from 'constexpr void fmt::v9::detail::buffer<T>::try_reserve(size_t) [with T = unsigned int]' at /data/src/build/common/fmt/include/fmt/core.h:928:39, inlined from 'constexpr void fmt::v9::detail::buffer<T>::try_reserve(size_t) [with T = unsigned int]' at /data/src/build/common/fmt/include/fmt/core.h:927:24, inlined from 'constexpr void fmt::v9::detail::buffer<T>::try_resize(size_t) [with T = unsigned int]' at /data/src/build/common/fmt/include/fmt/core.h:919:16, inlined from 'constexpr void fmt::v9::basic_memory_buffer<T, SIZE, Allocator>::resize(size_t) [with T = unsigned int; long unsigned int SIZE = 32; Allocator = std::allocator<unsigned int>]' at /data/src/build/common/fmt/include/fmt/format.h:897:63, inlined from 'constexpr void fmt::v9::detail::bigint::assign(UInt) [with UInt = long unsigned int; typename std::enable_if<(std::is_same<UInt, long unsigned int>::value || std::is_same<UInt, __int128 unsigned>::value), int>::type <anonymous> = 0]' at /data/src/build/common/fmt/include/fmt/format.h:2792:19, inlined from 'constexpr void fmt::v9::detail::bigint::operator=(Int) [with Int = 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=] 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 maybe 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 >= 0, ""); if (exp == 0) return *this = 1; //<== 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.
next reply other threads:[~2023-05-03 15:35 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-03 15:35 psmith at gnu dot org [this message] 2023-05-03 15:47 ` [Bug c++/109717] " psmith at gnu dot org 2023-05-03 16:37 ` redi at gcc dot gnu.org 2023-05-03 20:23 ` [Bug tree-optimization/109717] " psmith at gnu dot org 2023-05-03 20:34 ` redi at gcc dot gnu.org 2023-05-04 11:11 ` [Bug libstdc++/109717] " rguenth at gcc dot gnu.org 2023-05-04 11:13 ` [Bug tree-optimization/109717] " redi at gcc dot gnu.org 2023-05-04 11:16 ` redi at gcc dot gnu.org 2023-05-04 11:37 ` rguenth at gcc dot gnu.org 2023-05-04 13:30 ` psmith at gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-109717-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).