From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 30D0B385801E; Thu, 17 Mar 2022 12:31:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30D0B385801E From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104966] New: [11/12 Regression] Yet another bogus -Warray-bounds warning in libstdc++ headers Date: Thu, 17 Mar 2022 12:31:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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 keywords bug_severity priority component assigned_to reporter blocked target_milestone 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 12:31:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104966 Bug ID: 104966 Summary: [11/12 Regression] Yet another bogus -Warray-bounds warning in libstdc++ headers Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Blocks: 56456 Target Milestone: --- This has been failing for a while, but since there seems little chance of it getting fixed I didn't bother reporting it. This can be seen on any target with: make check RUNTESTFLAGS=3D"conformance.exp=3D22_locale/money_get/cons/3.cc --target_board=3Dunix/-std=3Dgnu++20" Executing on host: /home/jwakely/build/./gcc/xg++ -shared-libgcc -B/home/jwakely/build/./gcc -nostdinc++ -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/src -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/libsupc++/= .libs -B/home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/bin/ -B/home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/lib/ -isystem /home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/include -isystem /home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/sys-include -B/home/jwakely/build/powerpc64le-unknown-linux-gnu/./libstdc++-v3/src/.libs -fmessage-length=3D0 -fno-show-column -ffunction-sections -fdata-sections -= g -O2 -D_GNU_SOURCE -DLOCALEDIR=3D"." -nostdinc++ -I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/po= werpc64le-unknown-linux-gnu -I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include -I/home/jwakely/src/gcc/libstdc++-v3/libsupc++ -I/home/jwakely/src/gcc/libstdc++-v3/include/backward -I/home/jwakely/src/gcc/libstdc++-v3/testsuite/util /home/jwakely/src/gcc/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc= =20 -std=3Dgnu++20 -fdiagnostics-plain-output -S -o 3.s (timeout =3D 90) spawn -ignore SIGHUP /home/jwakely/build/./gcc/xg++ -shared-libgcc -B/home/jwakely/build/./gcc -nostdinc++ -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/src -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/libsupc++/= .libs -B/home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/bin/ -B/home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/lib/ -isystem /home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/include -isystem /home/jwakely/gcc/12/powerpc64le-unknown-linux-gnu/sys-include -B/home/jwakely/build/powerpc64le-unknown-linux-gnu/./libstdc++-v3/src/.libs -fmessage-length=3D0 -fno-show-column -ffunction-sections -fdata-sections -= g -O2 -D_GNU_SOURCE -DLOCALEDIR=3D"." -nostdinc++ -I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/po= werpc64le-unknown-linux-gnu -I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include -I/home/jwakely/src/gcc/libstdc++-v3/libsupc++ -I/home/jwakely/src/gcc/libstdc++-v3/include/backward -I/home/jwakely/src/gcc/libstdc++-v3/testsuite/util /home/jwakely/src/gcc/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc -std=3Dgnu++20 -fdiagnostics-plain-output -S -o 3.s In file included from /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/stri= ng:50, from /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_classes.h:40, from /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/loca= le:39, from /home/jwakely/src/gcc/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc:= 24: In static member function 'static constexpr _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _T= p*) [with _Tp =3D __gnu_cxx::character; bool _= IsMove =3D false]', inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:495, inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:522, inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:529, inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:620, inlined from 'static std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::char_type* std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::copy(char_type*, const char_type*, std::size_t) [with _Value =3D unsigne= d int; _Int =3D long unsigned int; _St =3D __mbstate_t]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/ext/= pod_char_traits.h:158, inlined from 'static std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::char_type* std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::copy(char_type*, const char_type*, std::size_t) [with _Value =3D unsigne= d int; _Int =3D long unsigned int; _St =3D __mbstate_t]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/ext/= pod_char_traits.h:154, inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.h:423, inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.h:418, inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::copy(_CharT*, size_type, size_type) const [with _CharT =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.tcc:555, inlined from 'void std::__moneypunct_cache<_CharT, _Intl>::_M_cache(con= st std::locale&) [with _CharT =3D __gnu_cxx::character; bool _Intl =3D false]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc:101: /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] In file included from /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.h:2069, from /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/loca= le:41: /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc: In member function 'void std::__moneypunct_cache<_CharT, _Intl>::_M_cache(c= onst std::locale&) [with _CharT =3D __gnu_cxx::character; bool _Intl =3D false]': /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc:100: note: destination object of size 0 allocated by 'operator new []' In static member function 'static constexpr _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _T= p*) [with _Tp =3D __gnu_cxx::character; bool _= IsMove =3D false]', inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:495, inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bo= ol _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:522, inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =3D false; _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:529, inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II =3D const __gnu_cxx::character*; _OI =3D __gnu_cxx::character*]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:620, inlined from 'static std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::char_type* std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::copy(char_type*, const char_type*, std::size_t) [with _Value =3D unsigne= d int; _Int =3D long unsigned int; _St =3D __mbstate_t]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/ext/= pod_char_traits.h:158, inlined from 'static std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::char_type* std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::copy(char_type*, const char_type*, std::size_t) [with _Value =3D unsigne= d int; _Int =3D long unsigned int; _St =3D __mbstate_t]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/ext/= pod_char_traits.h:154, inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.h:423, inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.h:418, inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::copy(_CharT*, size_type, size_type) const [with _CharT =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /basic_string.tcc:555, inlined from 'void std::__moneypunct_cache<_CharT, _Intl>::_M_cache(con= st std::locale&) [with _CharT =3D __gnu_cxx::character; bool _Intl =3D false]' at /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc:106: /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc: In member function 'void std::__moneypunct_cache<_CharT, _Intl>::_M_cache(c= onst std::locale&) [with _CharT =3D __gnu_cxx::character; bool _Intl =3D false]': /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /locale_facets_nonio.tcc:105: note: destination object of size 0 allocated by 'operator new []' FAIL: 22_locale/money_get/cons/3.cc (test for excess errors) Excess errors: /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] /home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/bits= /stl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' writing 1 or more bytes into a region of size 0 overflows the destination [-Wstringop-overflow=3D] The code allocates an array of n bytes and copies n bytes into it. If n=3D= =3D0 it copies 0 bytes. There's no overflow. const basic_string<_CharT>& __ns =3D __mp.negative_sign(); _M_negative_sign_size =3D __ns.size(); __negative_sign =3D new _CharT[_M_negative_sign_size]; __ns.copy(__negative_sign, _M_negative_sign_size); If you use -std=3Dgnu++20 -Wall there are more bogus warnings: /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/po= d_char_traits.h:107: warning: array subscript 0 is outside array bounds of '__gnu_cxx::character [0]' [-Warray-bounds] /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/po= d_char_traits.h:107: warning: array subscript 0 is outside array bounds of '__gnu_cxx::character [0]' [-Warray-bounds] /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/s= tl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' offset 0 is out of the bounds [0, 0] [-Warray-bounds] /home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/s= tl_algobase.h:431: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' offset 0 is out of the bounds [0, 0] [-Warray-bounds] I don't know why they're given twice but the "array subscript is outside ar= ray bounds" ones are: In file included from /home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/util/testsuite_character.h= :31, from /home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/22_locale/money_get/cons/3= .cc:25: In static member function 'static void std::char_traits<__gnu_cxx::character<_Value, _Int, _St> >::assign(char_typ= e&, const char_type&) [with _Value =3D unsigned int; _Int =3D long unsigned int= ; _St =3D __mbstate_t]', inlined from 'static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/gcc/12/include/c++/12.0.1/bits/basic_string.h:421:23, inlined from 'constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::copy(_CharT*, size_type, size_type) const [with _CharT =3D __gnu_cxx::character; _Traits =3D std::char_traits<__gnu_cxx::character >; _Alloc =3D std::allocator<__gnu_cxx::character >]' at /home/jwakely/gcc/12/include/c++/12.0.1/bits/basic_string.tcc:555:9, inlined from 'void std::__moneypunct_cache<_CharT, _Intl>::_M_cache(con= st std::locale&) [with _CharT =3D __gnu_cxx::character; bool _Intl =3D false]' at /home/jwakely/gcc/12/include/c++/12.0.1/bits/locale_facets_nonio.tcc:101:13: /home/jwakely/gcc/12/include/c++/12.0.1/ext/pod_char_traits.h:107:9: warnin= g: array subscript 0 is outside array bounds of '__gnu_cxx::character [0]' [-Warray-bounds] 107 | { __c1 =3D __c2; } | ^~~~ That comes from here: // When __n =3D 1 way faster than the general multichar // traits_type::copy/move/assign. _GLIBCXX20_CONSTEXPR static void _S_copy(_CharT* __d, const _CharT* __s, size_type __n) { if (__n =3D=3D 1) traits_type::assign(*__d, *__s); else traits_type::copy(__d, __s, __n); } The warning comes from the traits_type::assign call. The one guarded by __n= =3D=3D 1, so that it never happens if __n =3D=3D 0. MAKE IT STOP. PLEASE MAKE IT STOP. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds=