[Bug c++/105723] New: Optimization false positive warning
jeffrey.reynolds at ticketmaster dot com
gcc-bugzilla@gcc.gnu.org
Tue May 24 20:22:11 GMT 2022
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.
More information about the Gcc-bugs
mailing list