public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104966] New: [11/12 Regression] Yet another bogus -Warray-bounds warning in libstdc++ headers
@ 2022-03-17 12:31 redi at gcc dot gnu.org
  2022-03-17 12:35 ` [Bug middle-end/104966] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-17 12:31 UTC (permalink / raw)
  To: gcc-bugs

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

            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="conformance.exp=22_locale/money_get/cons/3.cc
--target_board=unix/-std=gnu++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=0 -fno-show-column -ffunction-sections -fdata-sections -g -O2
-D_GNU_SOURCE -DLOCALEDIR="." -nostdinc++
-I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/powerpc64le-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=gnu++20     -fdiagnostics-plain-output -S -o 3.s    (timeout = 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=0 -fno-show-column -ffunction-sections -fdata-sections -g -O2
-D_GNU_SOURCE -DLOCALEDIR="." -nostdinc++
-I/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/powerpc64le-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=gnu++20 -fdiagnostics-plain-output -S -o 3.s
In file included from
/home/jwakely/build/powerpc64le-unknown-linux-gnu/libstdc++-v3/include/string: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/locale: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*, _Tp*)
[with _Tp = __gnu_cxx::character<unsigned int, long unsigned int>; bool _IsMove
= false]',
    inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 bool
_IsMove = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = const
__gnu_cxx::character<unsigned int, long unsigned int>*; _OI =
__gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = unsigned int;
_Int = long unsigned int; _St = __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 = unsigned int;
_Int = long unsigned int; _St = __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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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(const
std::locale&) [with _CharT = __gnu_cxx::character<unsigned int, long unsigned
int>; bool _Intl = 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=]
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/locale: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(const
std::locale&) [with _CharT = __gnu_cxx::character<unsigned int, long unsigned
int>; bool _Intl = 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*, _Tp*)
[with _Tp = __gnu_cxx::character<unsigned int, long unsigned int>; bool _IsMove
= false]',
    inlined from 'constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 bool
_IsMove = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = false; _II = const __gnu_cxx::character<unsigned int, long unsigned
int>*; _OI = __gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = const
__gnu_cxx::character<unsigned int, long unsigned int>*; _OI =
__gnu_cxx::character<unsigned int, long unsigned int>*]' 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 = unsigned int;
_Int = long unsigned int; _St = __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 = unsigned int;
_Int = long unsigned int; _St = __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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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(const
std::locale&) [with _CharT = __gnu_cxx::character<unsigned int, long unsigned
int>; bool _Intl = 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=]
/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(const
std::locale&) [with _CharT = __gnu_cxx::character<unsigned int, long unsigned
int>; bool _Intl = 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=]
/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=]


The code allocates an array of n bytes and copies n bytes into it. If n==0 it
copies 0 bytes. There's no overflow.

          const basic_string<_CharT>& __ns = __mp.negative_sign();
          _M_negative_sign_size = __ns.size();
          __negative_sign = new _CharT[_M_negative_sign_size];
          __ns.copy(__negative_sign, _M_negative_sign_size);


If you use -std=gnu++20 -Wall there are more bogus warnings:

/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/pod_char_traits.h:107:
warning: array subscript 0 is outside array bounds of
'__gnu_cxx::character<unsigned int, long unsigned int> [0]' [-Warray-bounds]
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/pod_char_traits.h:107:
warning: array subscript 0 is outside array bounds of
'__gnu_cxx::character<unsigned int, long unsigned int> [0]' [-Warray-bounds]
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_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/stl_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 array
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_type&,
const char_type&) [with _Value = unsigned int; _Int = long unsigned int; _St =
__mbstate_t]',
    inlined from 'static constexpr void std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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 =
__gnu_cxx::character<unsigned int, long unsigned int>; _Traits =
std::char_traits<__gnu_cxx::character<unsigned int, long unsigned int> >;
_Alloc = std::allocator<__gnu_cxx::character<unsigned int, long unsigned int>
>]' 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(const
std::locale&) [with _CharT = __gnu_cxx::character<unsigned int, long unsigned
int>; bool _Intl = 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: warning:
array subscript 0 is outside array bounds of '__gnu_cxx::character<unsigned
int, long unsigned int> [0]' [-Warray-bounds]
  107 |       { __c1 = __c2; }
      |         ^~~~


That comes from here:

      // When __n = 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 == 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 ==
1, so that it never happens if __n == 0.

MAKE IT STOP. PLEASE MAKE IT STOP.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-04-21 12:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17 12:31 [Bug middle-end/104966] New: [11/12 Regression] Yet another bogus -Warray-bounds warning in libstdc++ headers redi at gcc dot gnu.org
2022-03-17 12:35 ` [Bug middle-end/104966] " redi at gcc dot gnu.org
2022-03-17 12:37 ` redi at gcc dot gnu.org
2022-03-17 12:39 ` redi at gcc dot gnu.org
2022-03-17 12:46 ` rguenth at gcc dot gnu.org
2022-03-17 12:48 ` rguenth at gcc dot gnu.org
2022-03-17 12:49 ` rguenth at gcc dot gnu.org
2022-03-17 12:51 ` redi at gcc dot gnu.org
2022-03-17 13:01 ` rguenth at gcc dot gnu.org
2022-03-17 17:52 ` cvs-commit at gcc dot gnu.org
2022-04-21  7:51 ` rguenth at gcc dot gnu.org
2022-04-21 12:32 ` cvs-commit at gcc dot gnu.org
2022-04-21 12:36 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).