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

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