public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-100366-4-LZ0ZiqAap2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100366-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100366

--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
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 just
a workaround, not a solution.

@@ -766,13 +766,16 @@
              {
                const size_type __len =
                  _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_storage);
                pointer __new_start(this->_M_allocate(__len));
                pointer __new_finish(__new_start);
                __try
                  {
                    __new_finish
                      = 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
                      = std::__uninitialized_copy_a(__first, __last,
@@ -780,7 +783,7 @@
                                                    _M_get_Tp_allocator());
                    __new_finish
                      = 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_finish,
+               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 = __new_start;
                this->_M_impl._M_finish = __new_finish;
                this->_M_impl._M_end_of_storage = __new_start + __len;

  parent reply	other threads:[~2021-05-05 11:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01  2:36 [Bug c++/100366] New: " mrsam@courier-mta.com
2021-05-02 11:27 ` [Bug tree-optimization/100366] " glisse at gcc dot gnu.org
2021-05-03 17:51 ` msebor at gcc dot gnu.org
2021-05-03 21:02 ` mrsam@courier-mta.com
2021-05-04  7:39 ` rguenth at gcc dot gnu.org
2021-05-05 10:55 ` glisse at gcc dot gnu.org
2021-05-05 11:01 ` glisse at gcc dot gnu.org
2021-05-05 11:15 ` glisse at gcc dot gnu.org [this message]
2021-05-05 12:18 ` mrsam@courier-mta.com
2021-05-12 23:44 ` msebor at gcc dot gnu.org
2021-12-02 21:14 ` msebor at gcc dot gnu.org
2021-12-06 16:45 ` [Bug tree-optimization/100366] [11/12 Regression] " roystgnr at ices dot utexas.edu
2021-12-28 12:09 ` pinskia at gcc dot gnu.org
2022-01-20 14:03 ` rguenth at gcc dot gnu.org
2022-04-21  7:49 ` rguenth at gcc dot gnu.org
2022-07-05 10:07 ` [Bug tree-optimization/100366] [11/12/13 " hewillk at gmail dot com
2022-11-26 15:53 ` zeranoe at gmail dot com
2022-11-29 15:58 ` redi at gcc dot gnu.org
2022-11-29 17:14 ` cvs-commit at gcc dot gnu.org
2023-04-20 13:57 ` [Bug tree-optimization/100366] [11/12 " cvs-commit at gcc dot gnu.org
2023-05-29 10:04 ` jakub at gcc dot gnu.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-100366-4-LZ0ZiqAap2@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: link
Be 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).