From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E07F43858C56; Thu, 13 Oct 2022 15:51:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E07F43858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665676284; bh=7g2pwLwv+B+CGlt0e8VnJx76xn+prG6G8XvUQfQD7kI=; h=From:To:Subject:Date:From; b=HB5klM0yV/jk3d7CWFZWeCkryC7EC2QGfMvKNGwJPmCIvbCXoZ1nhiCMVFiX3f2N7 HKZP9/H0soyHxhX9qwsOFKlV6Ptyqczpmd9YXMb6cLO8Q4QGBaKpltWdvX97HmgkP8 tYhAFcGP6KmuXXkFR0PW7ZFdEBedEQGiXch/A/Bw= From: "carlosgalvezp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107252] New: False positive stringop-overflow, warning disappears if I remove unrelated code! Date: Thu, 13 Oct 2022 15:51:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: carlosgalvezp at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107252 Bug ID: 107252 Summary: False positive stringop-overflow, warning disappears if I remove unrelated code! Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: carlosgalvezp at gmail dot com Target Milestone: --- Created attachment 53702 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53702&action=3Dedit Preprocessed source Hi,=20 I'm getting a false positive in the following reduced example (preprocessed source attached): #include #include class Test : public ::testing::Test { public: std::vector x_{}; }; struct Bar { std::vector a; std::vector b; }; TEST_F(Test, Test1) { const std::vector x{1}; const std::vector y(2, 1); std::vector z; z.insert(z.end(), x.begin(),x.end()); Bar bar{}; bar.a =3D z; } TEST_F(Test, Test2) { const std::vector z{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; Bar bar{}; bar.a =3D x_; } In file included from /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/algorithm:60, from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock= -actions.h:137, from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock= .h:56, from :1: In static member function 'static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [w= ith _Tp =3D unsigned char; bool _IsMove =3D true]', inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove= =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:497:30, inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove= =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:524:42, inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:531:31, inlined from '_OI std::copy(_II, _II, _OI) [with _II =3D move_iterator; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:624:7, inlined from 'static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterat= or, _ForwardIterator) [with _InputIterator =3D std::move_iterator; _ForwardIterator =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:147:27, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:185:15, inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterat= or, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*; _Tp =3D unsigned char]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:373:37, inlined from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator =3D unsigned char*; _ForwardIterator =3D unsigned char*; _Allocator =3D allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:399:2, inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/vector.tc= c:801:9, inlined from 'void std::vector<_Tp, _Alloc>::_M_insert_dispatch(iterato= r, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1779:19, inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; =3D void; _Tp =3D un= signed char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1481:22, inlined from 'virtual void Test_Test1_Test::TestBody()' at :23:= 13: /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:431:30: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] 431 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/x86_64-linux-g= nu/bits/c++allocator.h:33, from /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/allocator= .h:46, from /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/memory:65, from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock= -actions.h:139: In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, con= st void*) [with _Tp =3D unsigned char]', inlined from 'static _Tp* std::allocator_traits >::allocate(allocator_type&, size_type) [with _Tp =3D unsigned char]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/alloc_tra= its.h:468:28, inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp =3D unsi= gned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:378:33, inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/vector.tc= c:787:40, inlined from 'void std::vector<_Tp, _Alloc>::_M_insert_dispatch(iterato= r, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1779:19, inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; =3D void; _Tp =3D un= signed char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1481:22, inlined from 'virtual void Test_Test1_Test::TestBody()' at :23:= 13: /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/new_alloc= ator.h:144:55: note: at offset 1 into destination object of size 1 allocated by 'operator = new' 144 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); | ^ In static member function 'static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [w= ith _Tp =3D unsigned char; bool _IsMove =3D true]', inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove= =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:497:30, inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove= =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:524:42, inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = =3D true; _II =3D unsigned char*; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:531:31, inlined from '_OI std::copy(_II, _II, _OI) [with _II =3D move_iterator; _OI =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:624:7, inlined from 'static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterat= or, _ForwardIterator) [with _InputIterator =3D std::move_iterator; _ForwardIterator =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:147:27, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:185:15, inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterat= or, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator =3D move_iterator; _ForwardIterator =3D unsigned char*; _Tp =3D unsigned char]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:373:37, inlined from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator =3D unsigned char*; _ForwardIterator =3D unsigned char*; _Allocator =3D allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_unini= tialized.h:399:2, inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/vector.tc= c:801:9, inlined from 'void std::vector<_Tp, _Alloc>::_M_insert_dispatch(iterato= r, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1779:19, inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; =3D void; _Tp =3D un= signed char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1481:22, inlined from 'virtual void Test_Test1_Test::TestBody()' at :23:= 13: /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_algob= ase.h:431:30: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] 431 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, con= st void*) [with _Tp =3D unsigned char]', inlined from 'static _Tp* std::allocator_traits >::allocate(allocator_type&, size_type) [with _Tp =3D unsigned char]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/alloc_tra= its.h:468:28, inlined from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp =3D unsi= gned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:378:33, inlined from 'void std::vector<_Tp, _Alloc>::_M_range_insert(iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/vector.tc= c:787:40, inlined from 'void std::vector<_Tp, _Alloc>::_M_insert_dispatch(iterato= r, _InputIterator, _InputIterator, std::__false_type) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _Tp =3D unsigned char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1779:19, inlined from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; =3D void; _Tp =3D un= signed char; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/stl_vecto= r.h:1481:22, inlined from 'virtual void Test_Test1_Test::TestBody()' at :23:= 13: /opt/compiler-explorer/gcc-trunk-20221013/include/c++/13.0.0/bits/new_alloc= ator.h:144:55: note: at offset 1 into destination object of size 1 allocated by 'operator = new' 144 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); |=20=20=20=20=20=20=20=20=20=20 Compiling with flags:=20 -std=3Dc++14 -Wall -Wextra -pedantic -O3 -D_FORTIFY_SOURCE=3D1=20 Reproducible on Compiler Explorer: https://godbolt.org/z/3qs33fq9o If I remove anything that is not in use in this file, even if it's in a separate function, then the warning is gone. This tells me there must be something fishy going on. Do you have any hints as to what's happening? It looks totally random to me= !=