From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 98A473858404; Tue, 29 Nov 2022 16:50:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98A473858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669740618; bh=h9eyFmZ4bRSCB4F1yTGP5P/WbMVW8UCSh0Rxj76fCxQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HxTM7O83Gwg4cPNYGwYOBK3/4cWVuBQg7WklFV4gzKzXTHe/CZqG8jRB0XWnF1G1a UD1n6/uTMv7xeJgUn8XmVJS9irhCk7ik/OS5I+InXzOivkbkxDm/tpHiF//sJvrbf4 iWc6ArZGA2uq13TUACYsrSh6V5IxvNacCdAsNeUo= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107852] [12/13 Regression] Spurious warnings stringop-overflow and array-bounds copying data as bytes into vector Date: Tue, 29 Nov 2022 16:50:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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=3D107852 --- Comment #10 from Jonathan Wakely --- With that compiler patch for the missed-optimization one of the two bogus warnings goes away. The second one goes away with this change: --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -374,8 +374,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER pointer _M_allocate(size_t __n) { - typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; - return __n !=3D 0 ? _Tr::allocate(_M_impl, __n) : pointer(); + pointer __p =3D pointer(); + if (__n !=3D 0) + { + typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; + const pointer __s =3D _M_impl._M_start; + const pointer __f =3D _M_impl._M_finish; + const pointer __e =3D _M_impl._M_end_of_storage; + __p =3D _Tr::allocate(_M_impl, __n); + if (__s !=3D _M_impl._M_start || __f !=3D _M_impl._M_finish + || __e !=3D _M_impl._M_end_of_storage) + __builtin_unreachable(); + } + return __p; } _GLIBCXX20_CONSTEXPR=