From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F074439AE400; Wed, 5 May 2021 11:15:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F074439AE400 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100366] spurious warning - std::vector::clear followed by std::vector::insert(vec.end(), ...) with -O2 Date: Wed, 05 May 2021 11:15:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: glisse 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: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 11:15:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100366 --- Comment #7 from Marc Glisse --- It seems to help if we save the values before the allocation in vector.tcc, although I cannot promise it won't pessimize something else... And that's j= ust a workaround, not a solution. @@ -766,13 +766,16 @@ { const size_type __len =3D _M_check_len(__n, "vector::_M_range_insert"); + pointer __old_start(this->_M_impl._M_start); + pointer __old_finish(this->_M_impl._M_finish); + pointer __old_end_of_storage(this->_M_impl._M_end_of_storag= e); pointer __new_start(this->_M_allocate(__len)); pointer __new_finish(__new_start); __try { __new_finish =3D std::__uninitialized_move_if_noexcept_a - (this->_M_impl._M_start, __position.base(), + (__old_start, __position.base(), __new_start, _M_get_Tp_allocator()); __new_finish =3D std::__uninitialized_copy_a(__first, __last, @@ -780,7 +783,7 @@ _M_get_Tp_allocator()); __new_finish =3D std::__uninitialized_move_if_noexcept_a - (__position.base(), this->_M_impl._M_finish, + (__position.base(), __old_finish, __new_finish, _M_get_Tp_allocator()); } __catch(...) @@ -790,12 +793,12 @@ _M_deallocate(__new_start, __len); __throw_exception_again; } - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_fini= sh, + std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator()); _GLIBCXX_ASAN_ANNOTATE_REINIT; - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - - this->_M_impl._M_start); + _M_deallocate(__old_start, + __old_end_of_storage + - __old_start); this->_M_impl._M_start =3D __new_start; this->_M_impl._M_finish =3D __new_finish; this->_M_impl._M_end_of_storage =3D __new_start + __len;=