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.
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
Confirmed with GCC 12 but it seems that GCC 13 is no longer affected, possibly due to standard library changes.
Needs bisection as to what fixed it on trunk.
(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.
Dup of bug 107852 then. *** This bug has been marked as a duplicate of bug 107852 ***
(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!