stable_sort results may be corrupted with some g++ optimization options
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-defaults (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
On an amd64 system running Ubuntu 21.10, using g++ 11.2.0 (Ubuntu 11.2.0-7ubuntu2) to compile and run
```
#include <algorithm>
#include <cstdlib>
#include <vector>
int main(void)
{
std::
std::
for (auto & p : testvec)
if (p.second != 12345)
abort();
return 0;
}
```
with `g++ -O2 -funroll-loops -o test.exe test.C && ./test.exe`,
the compilation completes but the executable aborts. Examining testvec shows that testvec[0].second == 0. (In the more complex failures this was distilled from, the corrupted data may be non-zero, but so far I've only seen it at index 0.)
If I use 18 or fewer entries in the vector, the test passes. If I compile with -O0, -O1, or -O3, or if I omit -funroll-loops, or if I use g++ 10.3.0-11ubuntu1 (with -std=c++17 specified) it passes. If I use pair instead of tuple the test passes, though my original failure case was with a custom class there.
I haven't yet submitted this to GCC Bugzilla; they say they do not want "Bugs in releases or snapshots of GCC not issued by the GNU Project. Report them to whoever provided you with the release." and I'm not sure if the package I'm using counts as "issued by" them or whether it's been significantly patched downstream.
ProblemType: Bug
DistroRelease: Ubuntu 21.10
Package: g++ 4:11.2.0-1ubuntu1
ProcVersionSign
Uname: Linux 5.13.0-22-generic x86_64
ApportVersion: 2.20.11-0ubuntu71
Architecture: amd64
CasperMD5CheckR
CurrentDesktop: XFCE
Date: Mon Dec 6 15:42:56 2021
InstallationDate: Installed on 2021-02-15 (294 days ago)
InstallationMedia: Ubuntu 20.04.1 LTS "Focal Fossa" - Release amd64 (20200731)
SourcePackage: gcc-defaults
UpgradeStatus: Upgraded to impish on 2021-12-05 (1 days ago)