Public bug reported:

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::vector<std::pair<std::tuple<double,double>,int>> testvec(19, 
{{1,2},12345}); // 18- works
  std::stable_sort(testvec.begin(), testvec.end());
  
  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
ProcVersionSignature: Ubuntu 5.13.0-22.22-generic 5.13.19
Uname: Linux 5.13.0-22-generic x86_64
ApportVersion: 2.20.11-0ubuntu71
Architecture: amd64
CasperMD5CheckResult: unknown
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)

** Affects: gcc-defaults (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug impish

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1953401

Title:
  stable_sort results may be corrupted with some g++ optimization
  options

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1953401/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to