https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126617

            Bug ID: 126617
           Summary: std::map<std::vector<unsigned char>, int>
                    stringop-overread false positive at -O1/2/3
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: o.putaans at gmail dot com
  Target Milestone: ---

Created attachment 65221
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65221&action=edit
preprocessed temporary file of the minimum example

gcc -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
14.2.0-4ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr
--with-gcc-major-version-only --program-suffix=-14
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-14-FpLBWZ/gcc-14-14.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-14-FpLBWZ/gcc-14-14.2.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04.1) 

Minimum reproducible example:
```
#include <map>
#include <vector>

std::map<std::vector<unsigned char>, int> m;

int main()
{
    m[{}] = 1;
}

```
Compile command:
g++-14 -save-temps -O1 -std=c++23 -Werror=stringop-overread ../test.cpp

In file included from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/map:62,
                 from ../test.cpp:1:
In function ‘constexpr decltype (__comp((* __first1), (* __first2)))
std::lexicographical_compare_three_way(_InputIter1, _InputIter1, _InputIter2,
_InputIter2, _Comp) [with _InputIter1 = __gnu_cxx::__normal_iterator<const
unsigned char*, vector<unsigned char> >; _InputIter2 =
__gnu_cxx::__normal_iterator<const unsigned char*, vector<unsigned char> >;
_Comp = __detail::_Synth3way]’,
    inlined from ‘constexpr std::__detail::__synth3way_t<_Iterator>
std::operator<=>(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&) [with
_Tp = unsigned char; _Alloc = allocator<unsigned char>]’ at
/usr/include/c++/14/bits/stl_vector.h:2071:52,
    inlined from ‘constexpr bool std::less<_Tp>::operator()(const _Tp&, const
_Tp&) const [with _Tp = std::vector<unsigned char>]’ at
/usr/include/c++/14/bits/stl_function.h:405:20,
    inlined from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type&
std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key =
std::vector<unsigned char>; _Tp = int; _Compare =
std::less<std::vector<unsigned char> >; _Alloc = std::allocator<std::pair<const
std::vector<unsigned char>, int> >]’ at
/usr/include/c++/14/bits/stl_map.h:531:32,
    inlined from ‘int main()’ at ../test.cpp:8:9:
/usr/include/c++/14/bits/stl_algobase.h:1874:39: error: ‘int
__builtin_memcmp(const void*, const void*, long unsigned int)’ specified bound
[9223372036854775808, 18446744073709551615] exceeds maximum object size
9223372036854775807 [-Werror=stringop-overread]
 1874 |                     = __builtin_memcmp(&*__first1, &*__first2, __blen)
<=> 0;
      |                       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘constexpr decltype (__comp((* __first1), (* __first2)))
std::lexicographical_compare_three_way(_InputIter1, _InputIter1, _InputIter2,
_InputIter2, _Comp) [with _InputIter1 = __gnu_cxx::__normal_iterator<const
unsigned char*, vector<unsigned char> >; _InputIter2 =
__gnu_cxx::__normal_iterator<const unsigned char*, vector<unsigned char> >;
_Comp = __detail::_Synth3way]’,
    inlined from ‘constexpr std::__detail::__synth3way_t<_Iterator>
std::operator<=>(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&) [with
_Tp = unsigned char; _Alloc = allocator<unsigned char>]’ at
/usr/include/c++/14/bits/stl_vector.h:2071:52,
    inlined from ‘constexpr bool std::less<_Tp>::operator()(const _Tp&, const
_Tp&) const [with _Tp = std::vector<unsigned char>]’ at
/usr/include/c++/14/bits/stl_function.h:405:20,
    inlined from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::_M_lower_bound(_Link_type, _Base_ptr, const _Key&) [with _Key =
std::vector<unsigned char>; _Val = std::pair<const std::vector<unsigned char>,
int>; _KeyOfValue = std::_Select1st<std::pair<const std::vector<unsigned char>,
int> >; _Compare = std::less<std::vector<unsigned char> >; _Alloc =
std::allocator<std::pair<const std::vector<unsigned char>, int> >]’ at
/usr/include/c++/14/bits/stl_tree.h:1948:29,
    inlined from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare,
_Alloc>::lower_bound(const key_type&) [with _Key = std::vector<unsigned char>;
_Val = std::pair<const std::vector<unsigned char>, int>; _KeyOfValue =
std::_Select1st<std::pair<const std::vector<unsigned char>, int> >; _Compare =
std::less<std::vector<unsigned char> >; _Alloc = std::allocator<std::pair<const
std::vector<unsigned char>, int> >]’ at
/usr/include/c++/14/bits/stl_tree.h:1267:30,
    inlined from ‘std::map<_Key, _Tp, _Compare, _Alloc>::iterator
std::map<_Key, _Tp, _Compare, _Alloc>::lower_bound(const key_type&) [with _Key
= std::vector<unsigned char>; _Tp = int; _Compare =
std::less<std::vector<unsigned char> >; _Alloc = std::allocator<std::pair<const
std::vector<unsigned char>, int> >]’ at
/usr/include/c++/14/bits/stl_map.h:1308:32,
    inlined from ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type&
std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key =
std::vector<unsigned char>; _Tp = int; _Compare =
std::less<std::vector<unsigned char> >; _Alloc = std::allocator<std::pair<const
std::vector<unsigned char>, int> >]’ at
/usr/include/c++/14/bits/stl_map.h:529:28,
    inlined from ‘int main()’ at ../test.cpp:8:9:
/usr/include/c++/14/bits/stl_algobase.h:1874:39: error: ‘int
__builtin_memcmp(const void*, const void*, long unsigned int)’ specified bound
[9223372036854775808, 18446744073709551615] exceeds maximum object size
9223372036854775807 [-Werror=stringop-overread]
 1874 |                     = __builtin_memcmp(&*__first1, &*__first2, __blen)
<=> 0;
      |                       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors



This same code compiles if instead -O0 is specified or unsigned char is
replaced with char or unsigned int, or int.

Using Godbolt I managed to replicate this behaviour in GCC 14.4 and GCC 13.4

Reply via email to