From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DF0C83858D33; Sun, 9 Apr 2023 08:31:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF0C83858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681029115; bh=SlCtSsB7l6mnK5QKi/7fzZdGDpX5gFQCAJvvFNDouUQ=; h=From:To:Subject:Date:From; b=VOGWWl8SmmOTB84GPliz7ln3v6hkcRPB3ipY/eGNvwnYB0WyhAy5IxrUzmSKDaAIH YrzZuGjM9HZ/MVi8Rx64MMnY9DDxNz0E7jKu+i46AJefp4xCe737tJu1MZX2kSnrIj MAfC+mF8XwC6v5EajFKBuA4gnHXkctSJksERxUTU= From: "manx-bugzilla at problemloesungsmaschine dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109455] New: false-positive -Wstringop-overflow warning when using std::vector with UBsan Date: Sun, 09 Apr 2023 08:31:51 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: manx-bugzilla at problemloesungsmaschine dot de 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 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=3D109455 Bug ID: 109455 Summary: false-positive -Wstringop-overflow warning when using std::vector with UBsan Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: manx-bugzilla at problemloesungsmaschine dot de Target Milestone: --- ``` // g++ -std=3Dc++20 -fexceptions -frtti -pthread -fsanitize=3Dundefined -O3= -Wall -Wextra -Wpedantic -c test.cpp // GCC 12.2 #include #include struct Table { Table(); void SetSize(std::size_t size); std::vector m_Table; }; Table::Table() { m_Table.resize(42, 23); } void Table::SetSize(std::size_t size) { m_Table.resize(size); } ``` results in ``` In file included from /usr/include/c++/12/vector:60, from test.cpp:4: In static member function =E2=80=98static constexpr _Tp* std::__copy_move<_= IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _T= p*) [with _Tp =3D unsigned char; bool _IsMove =3D true]=E2=80=99, inlined from =E2=80=98constexpr _OI std::__copy_move_a2(_II, _II, _OI) = [with bool _IsMove =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]=E2=80=99 = at /usr/include/c++/12/bits/stl_algobase.h:495:30, inlined from =E2=80=98constexpr _OI std::__copy_move_a1(_II, _II, _OI) = [with bool _IsMove =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]=E2=80=99 = at /usr/include/c++/12/bits/stl_algobase.h:522:42, inlined from =E2=80=98constexpr _OI std::__copy_move_a(_II, _II, _OI) [= with bool _IsMove =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]=E2=80=99 = at /usr/include/c++/12/bits/stl_algobase.h:529:31, inlined from =E2=80=98constexpr _OI std::copy(_II, _II, _OI) [with _II = =3D move_iterator; _OI =3D unsigned char*]=E2=80=99 at /usr/include/c++/12/bits/stl_algobase.h:620:7, inlined from =E2=80=98static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterat= or, _ForwardIterator) [with _InputIterator =3D std::move_iterator; _ForwardIterator =3D unsigned char*]=E2=80=99 at /usr/include/c++/12/bits/stl_uninitialized.h:147:27, inlined from =E2=80=98_ForwardIterator std::uninitialized_copy(_InputIt= erator, _InputIterator, _ForwardIterator) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*]=E2=80=99 at /usr/include/c++/12/bits/stl_uninitialized.h:185:15, inlined from =E2=80=98constexpr _ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterato= r, allocator<_Tp>&) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*; _Tp =3D unsigned char]=E2=80=99 at /usr/include/c++/12/bits/stl_uninitialized.h:372:37, inlined from =E2=80=98constexpr _ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator =3D unsigned char*; _ForwardIterator =3D unsigned char*; _Allocator =3D allocator]=E2=80=99 at /usr/include/c++/12/bits/stl_uninitialized.h:397:2, inlined from =E2=80=98constexpr void std::vector<_Tp, _Alloc>::_M_fill_insert(iterator, size_type, const value_type&) [with _Tp = =3D unsigned char; _Alloc =3D std::allocator]=E2=80=99 at /usr/include/c++/12/bits/vector.tcc:594:7, inlined from =E2=80=98constexpr void std::vector<_Tp, _Alloc>::resize(s= ize_type, const value_type&) [with _Tp =3D unsigned char; _Alloc =3D std::allocator]=E2=80=99 at /usr/include/c++/12/bits/stl_vector.h:1032:18, inlined from =E2=80=98Table::Table()=E2=80=99 at test.cpp:14:16: /usr/include/c++/12/bits/stl_algobase.h:431:30: warning: =E2=80=98void* __builtin_memmove(void*, const void*, long unsigned int)=E2=80=99 writing 1= or more bytes into a region of size 0 overflows the destination [-Wstringop-overflo= w=3D] 431 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/12/bits/c++allocator.h:33, from /usr/include/c++/12/bits/allocator.h:46, from /usr/include/c++/12/vector:61: In member function =E2=80=98_Tp* std::__new_allocator<_Tp>::allocate(size_t= ype, const void*) [with _Tp =3D unsigned char]=E2=80=99, inlined from =E2=80=98constexpr _Tp* std::allocator< >::allocate(std::size_t) [with _Tp =3D unsigned char]=E2=80=99 at /usr/include/c++/12/bits/allocator.h:188:40, inlined from =E2=80=98static constexpr _Tp* std::allocator_traits >::allocate(allocator_type&, size_type) [with _Tp =3D unsigned char]=E2=80=99 at /usr/include/c++/12/bits/alloc_traits.h:464:28, inlined from =E2=80=98constexpr std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp =3D unsi= gned char; _Alloc =3D std::allocator]=E2=80=99 at /usr/include/c++/12/bits/stl_vector.h:378:33, inlined from =E2=80=98constexpr void std::vector<_Tp, _Alloc>::_M_fill_insert(iterator, size_type, const value_type&) [with _Tp = =3D unsigned char; _Alloc =3D std::allocator]=E2=80=99 at /usr/include/c++/12/bits/vector.tcc:575:45, inlined from =E2=80=98constexpr void std::vector<_Tp, _Alloc>::resize(s= ize_type, const value_type&) [with _Tp =3D unsigned char; _Alloc =3D std::allocator]=E2=80=99 at /usr/include/c++/12/bits/stl_vector.h:1032:18, inlined from =E2=80=98Table::Table()=E2=80=99 at test.cpp:14:16: /usr/include/c++/12/bits/new_allocator.h:137:55: note: at offset 42 into destination object of size 42 allocated by =E2=80=98operator new=E2=80=99 137 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); | ^ ``` ``` manx@appendix:~/tmp$ g++ --version g++ (Debian 12.2.0-14) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ``` godbolt: https://godbolt.org/z/17T47MvcK Does not happen with GCC trunk on godbolt. There are many similar bugs already reported, but I was not able to find any particularly good match. It might still be a duplicate though.=