public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105723] New: Optimization false positive warning
@ 2022-05-24 20:22 jeffrey.reynolds at ticketmaster dot com
  2022-05-25  7:34 ` [Bug libstdc++/105723] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jeffrey.reynolds at ticketmaster dot com @ 2022-05-24 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105723
           Summary: Optimization false positive warning
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffrey.reynolds at ticketmaster dot com
  Target Milestone: ---

The following code seems to be a regression, or an introduction of a bug.

```
#include <algorithm>
#include <cstdint>
#include <vector>

void some_func(const uint8_t* const& data) {
    std::vector<uint8_t> vec(data, data + 10);

    auto vecend = std::find_if(vec.rbegin(), vec.rend(), [](uint8_t x) {
        return x > 9;
    });

    if (vec.rend() != vecend) {
        vec = std::vector<uint8_t>();
    } else {
        std::transform(vec.rbegin(), vec.rend(), vec.rbegin(),
                       [](const uint8_t b) {
                           return (((b >> 4) & 0xf) | ((b & 0xf) << 4));
                       });
    }
}
```
https://godbolt.org/z/avzPEWKe7
This will cause a warning under GCC 12 (hard fail on my project)
I've checked previous versions of GCC along with several other compilers. All
compile it just fine.
There is nothing in this code that i can see that should be triggering a
stringop-overflow warning.
If the arch flag is remove, or the optimization turned down to O2 the code will
compile.
If you place `vec.resize(vec.size);` before the std::transform, which does
nothing since the size is neither less than nor greater than the current size,
the code will successfully compile. This last fact, along with the other facts,
indicates to me that it is indeed a bug.

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

* [Bug libstdc++/105723] Optimization false positive warning
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
@ 2022-05-25  7:34 ` rguenth at gcc dot gnu.org
  2022-10-25 22:41 ` [Bug tree-optimization/105723] [12/13 Regression] Optimization false positive warning (-Wstringop-overflow) pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-25  7:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
          Component|c++                         |libstdc++

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
In file included from
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/algorithm:61,
                 from <source>:1:
In function '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
[with _IIter = reverse_iterator<__gnu_cxx::__normal_iterator<unsigned char*,
vector<unsigned char> > >; _OIter =
reverse_iterator<__gnu_cxx::__normal_iterator<unsigned char*, vector<unsigned
char> > >; _UnaryOperation = some_func(const uint8_t*
const&)::<lambda(uint8_t)>]',
    inlined from 'void some_func(const uint8_t* const&)' at <source>:15:23:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/stl_algo.h:4263:19:
error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
 4263 |         *__result = __unary_op(*__first);
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1plus: some warnings being treated as errors
Compiler returned: 1

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

* [Bug tree-optimization/105723] [12/13 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
  2022-05-25  7:34 ` [Bug libstdc++/105723] " rguenth at gcc dot gnu.org
@ 2022-10-25 22:41 ` pinskia at gcc dot gnu.org
  2023-02-21 14:31 ` [Bug tree-optimization/105723] [12 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-25 22:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Optimization false positive |[12/13 Regression]
                   |warning                     |Optimization false positive
                   |(-Wstringop-overflow)       |warning
                   |                            |(-Wstringop-overflow)
   Target Milestone|---                         |12.3

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

* [Bug tree-optimization/105723] [12 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
  2022-05-25  7:34 ` [Bug libstdc++/105723] " rguenth at gcc dot gnu.org
  2022-10-25 22:41 ` [Bug tree-optimization/105723] [12/13 Regression] Optimization false positive warning (-Wstringop-overflow) pinskia at gcc dot gnu.org
@ 2023-02-21 14:31 ` rguenth at gcc dot gnu.org
  2023-04-27 11:33 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-21 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[12/13 Regression]          |[12 Regression]
                   |Optimization false positive |Optimization false positive
                   |warning                     |warning
                   |(-Wstringop-overflow)       |(-Wstringop-overflow)
   Last reconfirmed|                            |2023-02-21
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |13.0

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed with GCC 12 but it seems that GCC 13 is no longer affected, possibly
due to standard library changes.

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

* [Bug tree-optimization/105723] [12 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
                   ` (2 preceding siblings ...)
  2023-02-21 14:31 ` [Bug tree-optimization/105723] [12 " rguenth at gcc dot gnu.org
@ 2023-04-27 11:33 ` rguenth at gcc dot gnu.org
  2023-05-01  9:54 ` sjames at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-27 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Needs bisection as to what fixed it on trunk.

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

* [Bug tree-optimization/105723] [12 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
                   ` (3 preceding siblings ...)
  2023-04-27 11:33 ` rguenth at gcc dot gnu.org
@ 2023-05-01  9:54 ` sjames at gcc dot gnu.org
  2023-05-01 13:12 ` pinskia at gcc dot gnu.org
  2023-05-01 13:40 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-05-01  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenther at suse dot de

--- Comment #4 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)
> Needs bisection as to what fixed it on trunk.

Inverse bisect says:

fd8dd6c0384969170e594be34da278a072d5eb76 is the first bad commit
commit fd8dd6c0384969170e594be34da278a072d5eb76
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 29 12:56:22 2022 +0100

    tree-optimization/107852 - missed optimization with PHIs

i.e. r13-4389-gfd8dd6c0384969. It doesn't revert cleanly on trunk so I can't
test if it's sane or not.

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

* [Bug tree-optimization/105723] [12 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
                   ` (4 preceding siblings ...)
  2023-05-01  9:54 ` sjames at gcc dot gnu.org
@ 2023-05-01 13:12 ` pinskia at gcc dot gnu.org
  2023-05-01 13:40 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-01 13:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 107852 then.

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

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

* [Bug tree-optimization/105723] [12 Regression] Optimization false positive warning (-Wstringop-overflow)
  2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
                   ` (5 preceding siblings ...)
  2023-05-01 13:12 ` pinskia at gcc dot gnu.org
@ 2023-05-01 13:40 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-05-01 13:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> Dup of bug 107852 then.
> 
> *** This bug has been marked as a duplicate of bug 107852 ***

.. would've helped if i'd checked the bug referenced, ha. thank you!

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

end of thread, other threads:[~2023-05-01 13:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 20:22 [Bug c++/105723] New: Optimization false positive warning jeffrey.reynolds at ticketmaster dot com
2022-05-25  7:34 ` [Bug libstdc++/105723] " rguenth at gcc dot gnu.org
2022-10-25 22:41 ` [Bug tree-optimization/105723] [12/13 Regression] Optimization false positive warning (-Wstringop-overflow) pinskia at gcc dot gnu.org
2023-02-21 14:31 ` [Bug tree-optimization/105723] [12 " rguenth at gcc dot gnu.org
2023-04-27 11:33 ` rguenth at gcc dot gnu.org
2023-05-01  9:54 ` sjames at gcc dot gnu.org
2023-05-01 13:12 ` pinskia at gcc dot gnu.org
2023-05-01 13:40 ` sjames 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).