public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
@ 2022-09-29 14:35 redi at gcc dot gnu.org
  2023-03-09 20:48 ` [Bug tree-optimization/107087] " redi at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-29 14:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107087
           Summary: bits/stl_algobase.h:431: warning: 'void*
                    __builtin_memcpy(void*, const void*, unsigned int)'
                    reading between 8 and 2147483644 bytes from a region
                    of size 4 [-Wstringop-overread]
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---
            Target: i?86-pc-linux-gnu

Created attachment 53640
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53640&action=edit
Gzipped preprocessed output

There are bogus warnings when compiling the attached file using:

g++ -O2 3.ii -m32 -c

/usr/include/c++/12/bits/stl_algobase.h:431:30: warning: ‘void*
__builtin_memcpy(void*, const void*, unsigned int)’ reading between 8 and
2147483644 bytes from a region of size 4 [-Wstringop-overread]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:431:30: warning: ‘void*
__builtin_memcpy(void*, const void*, unsigned int)’ reading between 8 and
2147483644 bytes from a region of size 4 [-Wstringop-overread]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The warnings are still there on trunk, but -Warray-bounds instead of
-Wstringop-overread.

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

* [Bug tree-optimization/107087] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
@ 2023-03-09 20:48 ` redi at gcc dot gnu.org
  2023-03-09 20:49 ` [Bug tree-optimization/107087] [13 Regression] " redi at gcc dot gnu.org
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-09 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 54628
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54628&action=edit
Gzipped preprocessed output

Similar errors for this code with -std=c++20 -O2:

#include <vector>                                               

void test01()
{
  std::vector<int> v1, v2{5, 6};
  int n = 0;
  std::vector<int>::iterator it = v1.insert(v1.cbegin(), n);
  it = v1.insert(v1.cbegin(), 1);
  it = v1.insert(v1.cbegin(), {2, 3});
  it = v1.insert(v1.cbegin(), 1, 4);
  it = v1.insert(v1.cbegin(), v2.begin(), v2.end());
}

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
  2023-03-09 20:48 ` [Bug tree-optimization/107087] " redi at gcc dot gnu.org
@ 2023-03-09 20:49 ` redi at gcc dot gnu.org
  2023-03-15 10:00 ` rguenth at gcc dot gnu.org
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-09 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
      Known to fail|                            |13.0
      Known to work|                            |12.2.1
   Last reconfirmed|                            |2023-03-09
            Summary|bits/stl_algobase.h:431:    |[13 Regression]
                   |warning: 'void*             |bits/stl_algobase.h:431:
                   |__builtin_memcpy(void*,     |warning: 'void*
                   |const void*, unsigned int)' |__builtin_memcpy(void*,
                   |reading between 8 and       |const void*, unsigned int)'
                   |2147483644 bytes from a     |reading between 8 and
                   |region of size 4            |2147483644 bytes from a
                   |[-Wstringop-overread]       |region of size 4
                   |                            |[-Wstringop-overread]
             Status|UNCONFIRMED                 |NEW

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
  2023-03-09 20:48 ` [Bug tree-optimization/107087] " redi at gcc dot gnu.org
  2023-03-09 20:49 ` [Bug tree-optimization/107087] [13 Regression] " redi at gcc dot gnu.org
@ 2023-03-15 10:00 ` rguenth at gcc dot gnu.org
  2023-03-27 13:00 ` rguenth at gcc dot gnu.org
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-15 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
            Version|12.2.1                      |13.0

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-03-15 10:00 ` rguenth at gcc dot gnu.org
@ 2023-03-27 13:00 ` rguenth at gcc dot gnu.org
  2023-03-27 13:52 ` rguenth at gcc dot gnu.org
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-27 13:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Huh.

<bb 14> [local count: 226234232]:
_634 = _76 + _546;
_618 = -12;
if (_618 > 4)
  goto <bb 15>; [90.00%]
else
  goto <bb 16>; [10.00%]

left around by t.ii.204t.forwprop4

   _634 = _76 + _546;
-  _618 = 8 - prephitmp_260;
+  _618 = -12;
   if (_618 > 4)

and this constant is produced by cleanup_cfg via replace_uses_by which
replaces prephitmp_260 with 20 and folds the stmt when merging blocks
30 and 36.

If we'd realize the condition would be false we wouldn't emit the bad
diagnostics.  Note it's the very last forwprop and there's no copy
propagation done afterwards.  IMHO even CFG cleanup propagating to
uses instead of replacing the PHI with a copy is premature, so asking
for it to propagate even further there is wrong I think.

forwprop could eventually be taught to track known not executable edges
in its non-iterating RPO walk and so eventually optimize the copy itself.
The testcase has no loops at least.

Let me try.

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-03-27 13:00 ` rguenth at gcc dot gnu.org
@ 2023-03-27 13:52 ` rguenth at gcc dot gnu.org
  2023-03-27 14:00 ` redi at gcc dot gnu.org
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-27 13:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 54767
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54767&action=edit
patch I am testing

I can't verify the preprocessed sources with patched trunk.

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-03-27 13:52 ` rguenth at gcc dot gnu.org
@ 2023-03-27 14:00 ` redi at gcc dot gnu.org
  2023-03-28 13:25 ` cvs-commit at gcc dot gnu.org
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-27 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Comment 0 comes from 22_locale/money_put/cons/3.cc

make check RUNTESTFLAGS="conformance.exp=22_locale/money_put/cons/3.cc
--target_board=unix/-m32"

(but I don't see it failing now).

Comment 1 comes from 23_containers/vector/modifiers/insert/const_iterator.cc

make check
RUNTESTFLAGS="conformance.exp=23_containers/vector/modifiers/insert/const_iterator.cc
--target_board=unix/-std=c++20"

(this still fails with trunk)

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-03-27 14:00 ` redi at gcc dot gnu.org
@ 2023-03-28 13:25 ` cvs-commit at gcc dot gnu.org
  2023-03-28 13:26 ` rguenth at gcc dot gnu.org
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-28 13:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r13-6905-g2b9d76c1af189b918a9970f471e6d2e2c08f7e7d
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Mar 27 15:18:41 2023 +0200

    tree-optimization/107087 - missed CCP after forwprop

    When forwprop simplifies the CFG the 2nd order opportunities by
    exposed degenerate PHIs are not realized.  The following improves
    this by properly tracking executable edges and thus handling this
    for non-cyclic CFGs at least.

    This avoids the bogus diagnostic reported for the testcase in this PR.

            PR tree-optimization/107087
            * tree-ssa-forwprop.cc (pass_forwprop::execute): Track
            executable regions to avoid useless work and to better
            propagate degenerate PHIs.

            * g++.dg/pr107087.C: New testcase.

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-03-28 13:25 ` cvs-commit at gcc dot gnu.org
@ 2023-03-28 13:26 ` rguenth at gcc dot gnu.org
  2023-03-30  8:31 ` redi at gcc dot gnu.org
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-28 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

* [Bug tree-optimization/107087] [13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-03-28 13:26 ` rguenth at gcc dot gnu.org
@ 2023-03-30  8:31 ` redi at gcc dot gnu.org
  2023-03-31 11:36 ` [Bug tree-optimization/107087] [12/13 " rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-30  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> Comment 0 comes from 22_locale/money_put/cons/3.cc
> 
> make check RUNTESTFLAGS="conformance.exp=22_locale/money_put/cons/3.cc
> --target_board=unix/-m32"
> 
> (but I don't see it failing now).

I was using the wrong flags, with -m32 -D_GLIBCXX_DEBUG it fails on gcc-12:

Schedule of variations:
    unix/-m32/-D_GLIBCXX_USE_CXX11_ABI=0

Running target unix/-m32/-D_GLIBCXX_USE_CXX11_ABI=0
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for
target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/jwakely/src/gcc/gcc-12/libstdc++-v3/testsuite/config/default.exp as
tool-and-target-specific interface file.
Running
/home/jwakely/src/gcc/gcc-12/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp
...
FAIL: 22_locale/money_get/cons/3.cc (test for excess errors)
FAIL: 22_locale/money_put/cons/3.cc (test for excess errors)


And also still fails on trunk after r13-6905:

Schedule of variations:
    unix/-m32/-D_GLIBCXX_USE_CXX11_ABI=0

Running target unix/-m32/-D_GLIBCXX_USE_CXX11_ABI=0
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for
target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/config/default.exp as
tool-and-target-specific interface file.
Running
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp
...
FAIL: 22_locale/money_get/cons/3.cc (test for excess errors)
FAIL: 22_locale/money_put/cons/3.cc (test for excess errors)


Comment 1 is fixed on trunk now though, thanks.

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

* [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2023-03-30  8:31 ` redi at gcc dot gnu.org
@ 2023-03-31 11:36 ` rguenth at gcc dot gnu.org
  2023-03-31 11:55 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-31 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13 Regression]             |[12/13 Regression]
                   |bits/stl_algobase.h:431:    |bits/stl_algobase.h:431:
                   |warning: 'void*             |warning: 'void*
                   |__builtin_memcpy(void*,     |__builtin_memcpy(void*,
                   |const void*, unsigned int)' |const void*, unsigned int)'
                   |reading between 8 and       |reading between 8 and
                   |2147483644 bytes from a     |2147483644 bytes from a
                   |region of size 4            |region of size 4
                   |[-Wstringop-overread]       |[-Wstringop-overread]
             Status|RESOLVED                    |REOPENED
           Assignee|rguenth at gcc dot gnu.org         |unassigned at gcc dot gnu.org
         Resolution|FIXED                       |---
   Target Milestone|13.0                        |12.3

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Only comment#1 is fixed, the original testcase is 22_locale/money_get/cons/3.cc
which still fails with the settings from comment#7

We have

<bb 25> [local count: 268328082]:
_187 = MEM[(struct _Rep *)&_S_empty_rep_storage].D.58774._M_length;
_189 = MIN_EXPR <_170, _187>;
if (_189 != 0)
  goto <bb 26>; [50.00%]
else
  goto <bb 29>; [50.00%]

<bb 26> [local count: 134164041]:
if (_189 == 1)
  goto <bb 27>; [34.00%]
else
  goto <bb 28>; [66.00%]

<bb 27> [local count: 45615775]:
MEM[(struct char_type *)_172] = MEM[(const struct character
&)&_S_empty_rep_storage + 12];
goto <bb 29>; [100.00%]

<bb 28> [local count: 88548267]:
_173 = _189 * 4;
__builtin_memcpy (_172, &MEM <size_type[4]> [(void *)&_S_empty_rep_storage +
12B], _173);  // <--- diagnosed

<bb 29> [local count: 268328083]:
__negative_sign ={v} {CLOBBER};

so we know that _173 is [2, +INF] * 4 and that's enough to diagnose the
call as we seem to have an idea about the source size (the embedded
string length).

There's an intervening operator new preventing CSE of the length of the
destination and while there's a condition of != &_S_empty_rep_storage
control flow converges again before this, so it seems we handle both
here.

It's incredibly branchy code :/

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

* [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-03-31 11:36 ` [Bug tree-optimization/107087] [12/13 " rguenth at gcc dot gnu.org
@ 2023-03-31 11:55 ` redi at gcc dot gnu.org
  2023-03-31 12:43 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-31 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This prevents the warning:

--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -911,13 +911,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       ///  null-termination.
       size_type
       size() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+       if (_M_rep() == &_S_empty_rep() && _M_rep()->_M_length != 0)
+         __builtin_unreachable();
+#endif
+       return _M_rep()->_M_length;
+      }

       ///  Returns the number of characters in the string, not including any
       ///  null-termination.
       size_type
       length() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+       if (_M_rep() == &_S_empty_rep() && _M_rep()->_M_length != 0)
+         __builtin_unreachable();
+#endif
+       return _M_rep()->_M_length;
+      }

       ///  Returns the size() of the largest possible %string.
       size_type

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

* [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2023-03-31 11:55 ` redi at gcc dot gnu.org
@ 2023-03-31 12:43 ` redi at gcc dot gnu.org
  2023-03-31 22:45 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-31 12:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I wonder if some other hints about properties of the empty rep would help
codegen:

--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -204,6 +204,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        bool
        _M_is_leaked() const _GLIBCXX_NOEXCEPT
        {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+         if (_S_empty_rep()._M_refcount != 0)
+           __builtin_unreachable();
+#endif
+
 #if defined(__GTHREADS)
          // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
          // so we need to use an atomic load. However, _M_is_leaked
@@ -218,6 +223,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        bool
        _M_is_shared() const _GLIBCXX_NOEXCEPT
        {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+         if (_S_empty_rep()._M_refcount != 0)
+           __builtin_unreachable();
+#endif
+
 #if defined(__GTHREADS)
          // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
          // so we need to use an atomic load. Another thread can drop last
@@ -907,17 +917,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

     public:
       // Capacity:
+
       ///  Returns the number of characters in the string, not including any
       ///  null-termination.
       size_type
       size() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      {
+#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 && __OPTIMIZE__
+       if (_S_empty_rep()._M_length != 0)
+         __builtin_unreachable();
+#endif
+       return _M_rep()->_M_length;
+      }

       ///  Returns the number of characters in the string, not including any
       ///  null-termination.
       size_type
       length() const _GLIBCXX_NOEXCEPT
-      { return _M_rep()->_M_length; }
+      { return size(); }

       ///  Returns the size() of the largest possible %string.
       size_type

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

* [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2023-03-31 12:43 ` redi at gcc dot gnu.org
@ 2023-03-31 22:45 ` cvs-commit at gcc dot gnu.org
  2023-03-31 23:25 ` [Bug tree-optimization/107087] [12 " redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-31 22:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 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:4969dcd2b7a94ce6c0d07225b21b5f3c040a4902

commit r13-6962-g4969dcd2b7a94ce6c0d07225b21b5f3c040a4902
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Mar 31 13:44:04 2023 +0100

    libstdc++: Teach optimizer that empty COW strings are empty [PR107087]

    The compiler doesn't know about the invariant that the _S_empty_rep()
    object is immutable and so _M_length and _M_refcount are always zero.
    This means that we get warnings about writing possibly-non-zero length
    strings into buffers that can't hold them. If we teach the compiler that
    the empty rep is always zero length, it knows it can be copied into any
    buffer.

    For Stage 1 we might want to also consider adding this to capacity():

            if (_S_empty_rep()._M_capacity != 0)
              __builtin_unreachable();

    And this to _Rep::_M_is_leaked() and _Rep::_M_is_shared():

              if (_S_empty_rep()._M_refcount != 0)
                __builtin_unreachable();

    libstdc++-v3/ChangeLog:

            PR tree-optimization/107087
            * include/bits/cow_string.h (basic_string::size()): Add
            optimizer hint that _S_empty_rep()._M_length is always zero.
            (basic_string::length()): Call size().

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (12 preceding siblings ...)
  2023-03-31 22:45 ` cvs-commit at gcc dot gnu.org
@ 2023-03-31 23:25 ` redi at gcc dot gnu.org
  2023-04-27 11:50 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-31 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12/13 Regression]          |[12 Regression]
                   |bits/stl_algobase.h:431:    |bits/stl_algobase.h:431:
                   |warning: 'void*             |warning: 'void*
                   |__builtin_memcpy(void*,     |__builtin_memcpy(void*,
                   |const void*, unsigned int)' |const void*, unsigned int)'
                   |reading between 8 and       |reading between 8 and
                   |2147483644 bytes from a     |2147483644 bytes from a
                   |region of size 4            |region of size 4
                   |[-Wstringop-overread]       |[-Wstringop-overread]

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (13 preceding siblings ...)
  2023-03-31 23:25 ` [Bug tree-optimization/107087] [12 " redi at gcc dot gnu.org
@ 2023-04-27 11:50 ` rguenth at gcc dot gnu.org
  2023-04-27 12:00 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-27 11:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|12.2.1                      |11.3.0, 13.0
      Known to fail|13.0                        |12.2.0

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
I verified that picking this change fixes the diagnostic on the branch as well.
 I have no opinion as to how dangerous this is.

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (14 preceding siblings ...)
  2023-04-27 11:50 ` rguenth at gcc dot gnu.org
@ 2023-04-27 12:00 ` redi at gcc dot gnu.org
  2023-04-29  0:41 ` sjames at gcc dot gnu.org
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-27 12:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think it should be fine. I would prefer to wait until 12.4 so it has more
bake time, but that would just mean another few months of duplicate reports for
this issue.

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (15 preceding siblings ...)
  2023-04-27 12:00 ` redi at gcc dot gnu.org
@ 2023-04-29  0:41 ` sjames at gcc dot gnu.org
  2023-04-29  6:56 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-04-29  0:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #15 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #14)
> I think it should be fine. I would prefer to wait until 12.4 so it has more
> bake time, but that would just mean another few months of duplicate reports
> for this issue.

After chatting with jwakely, this is now on releases/gcc-12 as
r12-9486-g47880309516fd5 and we're rolling it out (the latest 12 snap) in
Gentoo. I expect everything will be fine but if it's not, you'll obviously hear
:)

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (16 preceding siblings ...)
  2023-04-29  0:41 ` sjames at gcc dot gnu.org
@ 2023-04-29  6:56 ` redi at gcc dot gnu.org
  2023-04-29  7:02 ` sjames at gcc dot gnu.org
  2023-05-08 12:25 ` rguenth at gcc dot gnu.org
  19 siblings, 0 replies; 21+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-29  6:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #16 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Sam James from comment #15)
> After chatting with jwakely, this is now on releases/gcc-12 as
> r12-9486-g47880309516fd5


That's a different fix for a different issue.

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (17 preceding siblings ...)
  2023-04-29  6:56 ` redi at gcc dot gnu.org
@ 2023-04-29  7:02 ` sjames at gcc dot gnu.org
  2023-05-08 12:25 ` rguenth at gcc dot gnu.org
  19 siblings, 0 replies; 21+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-04-29  7:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #17 from Sam James <sjames at gcc dot gnu.org> ---
... yes, it is - I saw one of the patches I'd backported didn't apply, assumed
must've been this one when I saw something in summary about uninitialised.

Anyway, I'll chuck it in now.

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

* [Bug tree-optimization/107087] [12 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread]
  2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
                   ` (18 preceding siblings ...)
  2023-04-29  7:02 ` sjames at gcc dot gnu.org
@ 2023-05-08 12:25 ` rguenth at gcc dot gnu.org
  19 siblings, 0 replies; 21+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

end of thread, other threads:[~2023-05-08 12:25 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 14:35 [Bug middle-end/107087] New: bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] redi at gcc dot gnu.org
2023-03-09 20:48 ` [Bug tree-optimization/107087] " redi at gcc dot gnu.org
2023-03-09 20:49 ` [Bug tree-optimization/107087] [13 Regression] " redi at gcc dot gnu.org
2023-03-15 10:00 ` rguenth at gcc dot gnu.org
2023-03-27 13:00 ` rguenth at gcc dot gnu.org
2023-03-27 13:52 ` rguenth at gcc dot gnu.org
2023-03-27 14:00 ` redi at gcc dot gnu.org
2023-03-28 13:25 ` cvs-commit at gcc dot gnu.org
2023-03-28 13:26 ` rguenth at gcc dot gnu.org
2023-03-30  8:31 ` redi at gcc dot gnu.org
2023-03-31 11:36 ` [Bug tree-optimization/107087] [12/13 " rguenth at gcc dot gnu.org
2023-03-31 11:55 ` redi at gcc dot gnu.org
2023-03-31 12:43 ` redi at gcc dot gnu.org
2023-03-31 22:45 ` cvs-commit at gcc dot gnu.org
2023-03-31 23:25 ` [Bug tree-optimization/107087] [12 " redi at gcc dot gnu.org
2023-04-27 11:50 ` rguenth at gcc dot gnu.org
2023-04-27 12:00 ` redi at gcc dot gnu.org
2023-04-29  0:41 ` sjames at gcc dot gnu.org
2023-04-29  6:56 ` redi at gcc dot gnu.org
2023-04-29  7:02 ` sjames at gcc dot gnu.org
2023-05-08 12:25 ` rguenth 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).