https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128217
Bug ID: 128217
Summary: [14/15 Regression] std::pair members incorrectly
compare equal with -O2 -mavx2
Product: gcc
Version: 15.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: reinsirk at ruri dot waseda.jp
Target Milestone: ---
Created attachment 65986
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65986&action=edit
Preprocessed main testcase; reproduces the assertion failure with GCC 15.3.0
GCC 15.1–15.3 miscompile this program on x86-64 with -O2 -mavx2. The
default C++ language mode is sufficient:
#include <cassert>
#include <vector>
#include <utility>
int main() {
std::vector<std::pair<int, int>> v(8);
for (int i = 0; i < 8; i++) v.at(i) = {i, i+2};
assert(v.front().second != v.front().first);
}
Save the program as repro.cpp, then compile and run it:
g++ -O2 -mavx2 repro.cpp -o repro
./repro
Expected: successful termination. The first pair should be {0, 2}, so
its members should differ.
Actual: compilation succeeds without diagnostics, but the executable
aborts because the assertion fails. With GCC 15.3.0, the diagnostic is:
repro: repro.cpp:8: int main(): Assertion `v.front().second !=
v.front().first' failed.
GCC 14.1–14.4 and 16.1/16.2 pass this testcase. GCC 15.1–15.3 pass
when -fno-tree-loop-vectorize is added.
[Compiler Explorer: GCC 15.3 and 16.2, -O2 -mavx2, execution output
only](https://godbolt.org/z/Pxe3W8j5a)
The attached break4.cpp is a second testcase with an explicit break.
Compile and run it with:
g++ -O2 -mavx2 break4.cpp -o break4
./break4
Expected: successful termination. The first output pair should be {1, 2}.
Actual: compilation succeeds without diagnostics, but the assertion
fails on GCC 14.1–14.4 and 15.1–15.3. With GCC 15.3.0, the diagnostic is:
break4: break4.cpp:17: int main(): Assertion `output[0].first !=
output[0].second' failed.
GCC 13.4 and 16.1/16.2 pass this testcase. Adding
-fno-tree-loop-vectorize also makes it pass on the affected versions.
In both testcases, members assigned different values compare equal on
the affected versions.
[Compiler Explorer: break4.cpp; GCC 14.4, 15.3 and 16.2, -O2
-mavx2](https://godbolt.org/z/ehfcGj7he)
The attached repro.ii and break4.ii are preprocessed testcases generated
with GCC 15.3.0. Both reproduce the assertion failures when compiled with
-O2 -mavx2, without a -std option. The attached compiler.txt contains the
GCC 15.3.0 configuration and version information from g++ -v; its target
is x86_64-pc-linux-gnu.
Credits and AI assistance: I found the failure in my original program
and identified it as a compiler issue. Tasuku Sato created the original
minimal pair/vector testcase and isolated the compiler options.
I created break4.cpp based on an exploratory testcase generated by OpenAI
Codex.
Codex also assisted with testing, analysis, and drafting this report.