public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111415] New: False positive array-bounds warning with -O3
@ 2023-09-14 13:14 daiw at gmx dot net
  2023-09-14 15:00 ` [Bug tree-optimization/111415] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: daiw at gmx dot net @ 2023-09-14 13:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111415
           Summary: False positive array-bounds warning with -O3
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daiw at gmx dot net
  Target Milestone: ---

Using g++ (GCC) 13.2.0,

the following minimal example:



std::vector<int> foo(const std::vector<int>& a)
{
    if (a.size() < 2)
    {
        return a;
    }
    return a;
}

int main()
{
    foo(std::vector<int>({1}));
}



Produces a warning when trying to compile like so:


g++ -Wall -O3 main.cpp



Output:


In file included from /usr/local/include/c++/13.2.0/vector:62,
                 from main.cpp:1:
In static member function 'static _Up* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const
int; _Up = int; bool _IsMove = false]',
    inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove =
false; _II = const int*; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:506:30,
    inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove =
false; _II = const int*; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:533:42,
    inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =
false; _II = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI =
int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:540:31,
    inlined from '_OI std::copy(_II, _II, _OI) [with _II =
__gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:633:7,
    inlined from 'static _ForwardIterator
std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator,
_ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const
int*, std::vector<int> >; _ForwardIterator = int*]' at
/usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:147:27,
    inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator =
int*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:185:15,
    inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator,
_InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator =
__gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator =
int*; _Tp = int]' at
/usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:373:37,
    inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]' at
/usr/local/include/c++/13.2.0/bits/stl_vector.h:603:31,
    inlined from 'std::vector<int> foo(const std::vector<int>&)' at
main.cpp:7:16:
/usr/local/include/c++/13.2.0/bits/stl_algobase.h:437:30: warning: 'void*
__builtin_memmove(void*, const void*, long unsigned int)' forming offset 4 is
out of the bounds [0, 4] [-Warray-bounds=]
  437 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* [Bug tree-optimization/111415] False positive array-bounds warning with -O3
  2023-09-14 13:14 [Bug c++/111415] New: False positive array-bounds warning with -O3 daiw at gmx dot net
@ 2023-09-14 15:00 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-14 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am pretty sure there is a dup of this bug already.

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

end of thread, other threads:[~2023-09-14 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 13:14 [Bug c++/111415] New: False positive array-bounds warning with -O3 daiw at gmx dot net
2023-09-14 15:00 ` [Bug tree-optimization/111415] " 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).