public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106199] New: vector::insert optimization is broken with gcc-12
@ 2022-07-05 10:02 hewillk at gmail dot com
  2022-07-05 10:07 ` [Bug c++/106199] " hewillk at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: hewillk at gmail dot com @ 2022-07-05 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106199
           Summary: vector::insert optimization is broken with gcc-12
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

Example from
https://stackoverflow.com/questions/72867072/why-g12-vector-insert-optimization-breaks-code

#include <vector>
#include <array>

std::vector<int> s_to_bytes() {
  std::vector<int> res;
  std::array<int, 4> s{};
  res.insert(res.begin(), s.begin(), s.end());
  return res;
}

https://godbolt.org/z/4YrzTso9o

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/106199] vector::insert optimization is broken with gcc-12
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
@ 2022-07-05 10:07 ` hewillk at gmail dot com
  2022-07-05 10:18 ` hewillk at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hewillk at gmail dot com @ 2022-07-05 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

康桓瑋 <hewillk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
dup of PR100366

*** This bug has been marked as a duplicate of bug 100366 ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/106199] vector::insert optimization is broken with gcc-12
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
  2022-07-05 10:07 ` [Bug c++/106199] " hewillk at gmail dot com
@ 2022-07-05 10:18 ` hewillk at gmail dot com
  2022-07-05 16:30 ` [Bug middle-end/106199] " redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hewillk at gmail dot com @ 2022-07-05 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

康桓瑋 <hewillk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |UNCONFIRMED

--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
This may not be the dup of PR100366.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/106199] vector::insert optimization is broken with gcc-12
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
  2022-07-05 10:07 ` [Bug c++/106199] " hewillk at gmail dot com
  2022-07-05 10:18 ` hewillk at gmail dot com
@ 2022-07-05 16:30 ` redi at gcc dot gnu.org
  2022-07-05 23:17 ` [Bug tree-optimization/106199] incorrect memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-05 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |middle-end

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, optimization is not broken. It's a bogus warning, that's all.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] incorrect memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert .
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2022-07-05 16:30 ` [Bug middle-end/106199] " redi at gcc dot gnu.org
@ 2022-07-05 23:17 ` pinskia at gcc dot gnu.org
  2022-07-05 23:17 ` [Bug tree-optimization/106199] [12 Regression] incorrect warning: " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-05 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |tree-optimization
            Summary|vector::insert optimization |incorrect memcpy writing 1
                   |is broken with gcc-12       |or more bytes into a region
                   |                            |of size 0 overflows the
                   |                            |destination with
                   |                            |std::vector::insert .

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
/opt/compiler-explorer/gcc-trunk-20220705/include/c++/13.0.0/bits/stl_algobase.h:431:30:
error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing
1 or more bytes into a region of size 0 overflows the destination
[-Werror=stringop-overflow=]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] [12 Regression] incorrect warning: memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2022-07-05 23:17 ` [Bug tree-optimization/106199] incorrect memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert pinskia at gcc dot gnu.org
@ 2022-07-05 23:17 ` pinskia at gcc dot gnu.org
  2022-07-25 15:15 ` [Bug tree-optimization/106199] [12/13 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-05 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|incorrect memcpy writing 1  |[12 Regression] incorrect
                   |or more bytes into a region |warning: memcpy writing 1
                   |of size 0 overflows the     |or more bytes into a region
                   |destination with            |of size 0 overflows the
                   |std::vector::insert .       |destination with
                   |                            |std::vector::insert
   Target Milestone|---                         |12.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] [12/13 Regression] incorrect warning: memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2022-07-05 23:17 ` [Bug tree-optimization/106199] [12 Regression] incorrect warning: " pinskia at gcc dot gnu.org
@ 2022-07-25 15:15 ` rguenth at gcc dot gnu.org
  2022-11-29 15:58 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-25 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-07-25
             Status|UNCONFIRMED                 |NEW
           Priority|P3                          |P2
     Ever confirmed|0                           |1

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed with -O2.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] [12/13 Regression] incorrect warning: memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (5 preceding siblings ...)
  2022-07-25 15:15 ` [Bug tree-optimization/106199] [12/13 " rguenth at gcc dot gnu.org
@ 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 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-29 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to 康桓瑋 from comment #2)
> This may not be the dup of PR100366.

It looks exactly the same to me, and is fixed by the patch for that bug.

*** This bug has been marked as a duplicate of bug 100366 ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] [12/13 Regression] incorrect warning: memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (6 preceding siblings ...)
  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 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-29 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:cca06f0d6d76b08ed4ddb7667eda93e2e9f2589e

commit r13-4393-gcca06f0d6d76b08ed4ddb7667eda93e2e9f2589e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 29 15:50:06 2022 +0000

    libstdc++: Avoid bogus warning in std::vector::insert [PR107852]

    GCC assumes that any global variable might be modified by operator new,
    and so in the testcase for this PR all data members get reloaded after
    allocating new storage. By making local copies of the _M_start and
    _M_finish members we avoid that, and then the compiler has enough info
    to remove the dead branches that trigger bogus -Warray-bounds warnings.

    libstdc++-v3/ChangeLog:

            PR libstdc++/107852
            PR libstdc++/106199
            PR libstdc++/100366
            * include/bits/vector.tcc (vector::_M_fill_insert): Copy
            _M_start and _M_finish members before allocating.
            (vector::_M_default_append): Likewise.
            (vector::_M_range_insert): Likewise.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug tree-optimization/106199] [12/13 Regression] incorrect warning: memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert
  2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
                   ` (7 preceding siblings ...)
  2022-11-29 17:14 ` cvs-commit at gcc dot gnu.org
@ 2023-04-20 13:57 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-20 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:2e4210698c644e44f9e0645dc7bc49710fd60ce8

commit r12-9457-g2e4210698c644e44f9e0645dc7bc49710fd60ce8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 29 15:50:06 2022 +0000

    libstdc++: Avoid bogus warning in std::vector::insert [PR107852]

    GCC assumes that any global variable might be modified by operator new,
    and so in the testcase for this PR all data members get reloaded after
    allocating new storage. By making local copies of the _M_start and
    _M_finish members we avoid that, and then the compiler has enough info
    to remove the dead branches that trigger bogus -Warray-bounds warnings.

    libstdc++-v3/ChangeLog:

            PR libstdc++/107852
            PR libstdc++/106199
            PR libstdc++/100366
            * include/bits/vector.tcc (vector::_M_fill_insert): Copy
            _M_start and _M_finish members before allocating.
            (vector::_M_default_append): Likewise.
            (vector::_M_range_insert): Likewise.

    (cherry picked from commit cca06f0d6d76b08ed4ddb7667eda93e2e9f2589e)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-04-20 13:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 10:02 [Bug c++/106199] New: vector::insert optimization is broken with gcc-12 hewillk at gmail dot com
2022-07-05 10:07 ` [Bug c++/106199] " hewillk at gmail dot com
2022-07-05 10:18 ` hewillk at gmail dot com
2022-07-05 16:30 ` [Bug middle-end/106199] " redi at gcc dot gnu.org
2022-07-05 23:17 ` [Bug tree-optimization/106199] incorrect memcpy writing 1 or more bytes into a region of size 0 overflows the destination with std::vector::insert pinskia at gcc dot gnu.org
2022-07-05 23:17 ` [Bug tree-optimization/106199] [12 Regression] incorrect warning: " pinskia at gcc dot gnu.org
2022-07-25 15:15 ` [Bug tree-optimization/106199] [12/13 " rguenth at gcc dot gnu.org
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 ` cvs-commit at gcc dot gnu.org

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).