public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109455] New: false-positive -Wstringop-overflow warning when using std::vector with UBsan
@ 2023-04-09  8:31 manx-bugzilla at problemloesungsmaschine dot de
  2023-04-09 16:25 ` [Bug tree-optimization/109455] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: manx-bugzilla at problemloesungsmaschine dot de @ 2023-04-09  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109455
           Summary: false-positive -Wstringop-overflow warning when using
                    std::vector with UBsan
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manx-bugzilla at problemloesungsmaschine dot de
  Target Milestone: ---

```
// g++ -std=c++20 -fexceptions -frtti -pthread -fsanitize=undefined -O3 -Wall
-Wextra -Wpedantic -c test.cpp
// GCC 12.2

#include <vector>
#include <cstddef>

struct Table {
        Table();
        void SetSize(std::size_t size);
        std::vector<unsigned char> m_Table;
};

Table::Table() {
        m_Table.resize(42, 23);
}

void Table::SetSize(std::size_t size) {
        m_Table.resize(size);
}
```

results in

```
In file included from /usr/include/c++/12/vector:60,
                 from test.cpp:4:
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 = unsigned char; bool _IsMove = true]’,
    inlined from ‘constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool
_IsMove = true; _II = unsigned char*; _OI = unsigned char*]’ at
/usr/include/c++/12/bits/stl_algobase.h:495:30,
    inlined from ‘constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool
_IsMove = true; _II = unsigned char*; _OI = unsigned char*]’ at
/usr/include/c++/12/bits/stl_algobase.h:522:42,
    inlined from ‘constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool
_IsMove = true; _II = unsigned char*; _OI = unsigned char*]’ at
/usr/include/c++/12/bits/stl_algobase.h:529:31,
    inlined from ‘constexpr _OI std::copy(_II, _II, _OI) [with _II =
move_iterator<unsigned char*>; _OI = unsigned char*]’ at
/usr/include/c++/12/bits/stl_algobase.h:620:7,
    inlined from ‘static _ForwardIterator
std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator,
_ForwardIterator) [with _InputIterator = std::move_iterator<unsigned char*>;
_ForwardIterator = unsigned char*]’ at
/usr/include/c++/12/bits/stl_uninitialized.h:147:27,
    inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator = move_iterator<unsigned
char*>; _ForwardIterator = unsigned char*]’ at
/usr/include/c++/12/bits/stl_uninitialized.h:185:15,
    inlined from ‘constexpr _ForwardIterator
std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator,
allocator<_Tp>&) [with _InputIterator = move_iterator<unsigned char*>;
_ForwardIterator = unsigned char*; _Tp = unsigned char]’ at
/usr/include/c++/12/bits/stl_uninitialized.h:372:37,
    inlined from ‘constexpr _ForwardIterator
std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator,
_ForwardIterator, _Allocator&) [with _InputIterator = unsigned char*;
_ForwardIterator = unsigned char*; _Allocator = allocator<unsigned char>]’ at
/usr/include/c++/12/bits/stl_uninitialized.h:397:2,
    inlined from ‘constexpr void std::vector<_Tp,
_Alloc>::_M_fill_insert(iterator, size_type, const value_type&) [with _Tp =
unsigned char; _Alloc = std::allocator<unsigned char>]’ at
/usr/include/c++/12/bits/vector.tcc:594:7,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::resize(size_type,
const value_type&) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned
char>]’ at /usr/include/c++/12/bits/stl_vector.h:1032:18,
    inlined from ‘Table::Table()’ at test.cpp:14:16:
/usr/include/c++/12/bits/stl_algobase.h:431:30: 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=]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/usr/include/x86_64-linux-gnu/c++/12/bits/c++allocator.h:33,
                 from /usr/include/c++/12/bits/allocator.h:46,
                 from /usr/include/c++/12/vector:61:
In member function ‘_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = unsigned char]’,
    inlined from ‘constexpr _Tp* std::allocator< <template-parameter-1-1>
>::allocate(std::size_t) [with _Tp = unsigned char]’ at
/usr/include/c++/12/bits/allocator.h:188:40,
    inlined from ‘static constexpr _Tp*
std::allocator_traits<std::allocator<_Up> >::allocate(allocator_type&,
size_type) [with _Tp = unsigned char]’ at
/usr/include/c++/12/bits/alloc_traits.h:464:28,
    inlined from ‘constexpr std::_Vector_base<_Tp, _Alloc>::pointer
std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = unsigned
char; _Alloc = std::allocator<unsigned char>]’ at
/usr/include/c++/12/bits/stl_vector.h:378:33,
    inlined from ‘constexpr void std::vector<_Tp,
_Alloc>::_M_fill_insert(iterator, size_type, const value_type&) [with _Tp =
unsigned char; _Alloc = std::allocator<unsigned char>]’ at
/usr/include/c++/12/bits/vector.tcc:575:45,
    inlined from ‘constexpr void std::vector<_Tp, _Alloc>::resize(size_type,
const value_type&) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned
char>]’ at /usr/include/c++/12/bits/stl_vector.h:1032:18,
    inlined from ‘Table::Table()’ at test.cpp:14:16:
/usr/include/c++/12/bits/new_allocator.h:137:55: note: at offset 42 into
destination object of size 42 allocated by ‘operator new’
  137 |         return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
      |                                                       ^
```

```
manx@appendix:~/tmp$ g++ --version
g++ (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

godbolt: https://godbolt.org/z/17T47MvcK

Does not happen with GCC trunk on godbolt.

There are many similar bugs already reported, but I was not able to find any
particularly good match. It might still be a duplicate though.

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

* [Bug tree-optimization/109455] false-positive -Wstringop-overflow warning when using std::vector with UBsan
  2023-04-09  8:31 [Bug c++/109455] New: false-positive -Wstringop-overflow warning when using std::vector with UBsan manx-bugzilla at problemloesungsmaschine dot de
@ 2023-04-09 16:25 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-09 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
          Component|c++                         |tree-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined


Note that sanitizers tend to increase the rate of false positive warnings, most
notably those around -Wmaybe-uninitialized. We recommend against combining
-Werror and [the use of] sanitizers.

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

end of thread, other threads:[~2023-04-09 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-09  8:31 [Bug c++/109455] New: false-positive -Wstringop-overflow warning when using std::vector with UBsan manx-bugzilla at problemloesungsmaschine dot de
2023-04-09 16:25 ` [Bug tree-optimization/109455] " pinskia 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).