https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122868
Bug ID: 122868
Summary: [16 Regression] Wrong code generated for vector<bool>
operator==
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kacper.slominski72 at gmail dot com
Target Milestone: ---
Originally found in Kicad 9.0.4 and reduced from there.
The following code, when compiled for x86_64 with the `-O3 -mavx2` flags (using
`-O2`, not enabling AVX2, adding `-fno-tree-vectorize` all work around the
issue), segfaults at runtime:
#include <vector>
std::vector<bool> x, y;
int main() { return x == y; }
Looking at the binary in gdb, the crash is on a load from nullptr:
Program received signal SIGSEGV, Segmentation fault.
0x00005555555551ad in std::operator== (__x=..., __y=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_bvector.h:250
250 return __x._M_p == __y._M_p && __x._M_offset == __y._M_offset;
(gdb) bt
#0 0x00005555555551ad in std::operator== (__x=..., __y=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_bvector.h:250
#1 std::__equal<false>::equal<std::_Bit_const_iterator,
std::_Bit_const_iterator> (__first1=..., __last1=..., __first2=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_algobase.h:1199
#2 std::__equal_aux1<std::_Bit_const_iterator, std::_Bit_const_iterator>
(__first1=..., __last1=..., __first2=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_algobase.h:1255
#3 std::__equal_aux<std::_Bit_const_iterator, std::_Bit_const_iterator>
(__first1=..., __last1=..., __first2=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_algobase.h:1264
#4 std::equal<std::_Bit_const_iterator, std::_Bit_const_iterator>
(__first1=..., __last1=..., __first2=...) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_algobase.h:1606
#5 std::operator==<bool, std::allocator<bool> > (__x=std::vector<bool> of
length 0, capacity 0, __y=std::vector<bool> of length 0, capacity 0) at
/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16/bits/stl_vector.h:2335
#6 main () at test.cpp:5
(gdb) x/i $pc
=> 0x5555555551ad <main()+301>: mov (%rsi),%r11
(gdb) p/x $rsi
$1 = 0x0
(gdb)
gcc version:
gcc (Gentoo 16.0.9999 p, commit d93ac8e926116356695925acea88cb496d9ddaa8)
16.0.0 20251126 (experimental) 4e7213aa081f1c0ca5b7e6a60d4e7ba5bcfb1f8a