public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
@ 2024-01-04 20:45 dimitry@unified-streaming.com
2024-01-04 21:10 ` [Bug tree-optimization/113239] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: dimitry@unified-streaming.com @ 2024-01-04 20:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
Bug ID: 113239
Summary: [13 regression] After 822a11a1e64, bogus
-Warray-bounds warnings in std::vector
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dimitry@unified-streaming.com
Target Milestone: ---
We noticed spurious warnings in some C++17 code compiled with g++ 13.2.0, and I
bisected it to commit 822a11a1e642e0abe92a996e7033a5066905a447 ("libstdc++: Do
not use memmove for 1-element ranges [PR108846]") for bug 108846 ("std::copy,
std::copy_n and std::copy_backward on potentially overlapping subobjects").
Reduced test case:
// g++ -std=c++17 -Wall -O2 -c testcase.cpp
#include <cstdint>
#include <vector>
struct frame_t
{
uint64_t pts_;
uint32_t timescale_;
std::vector<uint8_t> data_;
};
struct frame_source_t
{
virtual frame_t get() = 0;
};
struct frame_filter_t : frame_source_t
{
frame_t get() override
{
if(current_frame_.data_.empty())
{
return current_frame_;
}
else
{
return frame_t();
}
}
frame_t current_frame_;
};
frame_filter_t create_frame_filter()
{
return frame_filter_t();
}
// EOT
With gcc-13-6371-ga41a56dee5c, this compiles without any warning. With
gcc-13-6372-g822a11a1e64 and later, up to gcc-14-6924-g00dea7e8c41 (master as
of 2024-01-04), you get:
In file included from
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/vector:62,
from testcase.cpp:5:
In static member function 'static void std::__copy_move<false, false,
std::random_access_iterator_tag>::__assign_one(_Tp*, _Up*) [with _Tp = unsigned
char; _Up = const unsigned char]',
inlined from 'static _Up* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const
unsigned char; _Up = unsigned char; bool _IsMove = false]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:441:20,
inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove =
false; _II = const unsigned char*; _OI = unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:507:30,
inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove =
false; _II = const unsigned char*; _OI = unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:534:42,
inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove =
false; _II = __gnu_cxx::__normal_iterator<const unsigned char*, vector<unsigned
char> >; _OI = unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:541:31,
inlined from '_OI std::copy(_II, _II, _OI) [with _II =
__gnu_cxx::__normal_iterator<const unsigned char*, vector<unsigned char> >; _OI
= unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:637:7,
inlined from 'static _ForwardIterator
std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator,
_ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const
unsigned char*, std::vector<unsigned char> >; _ForwardIterator = unsigned
char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_uninitialized.h:147:27,
inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<const unsigned char*, vector<unsigned char> >;
_ForwardIterator = unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.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 unsigned char*, vector<unsigned char> >;
_ForwardIterator = unsigned char*; _Tp = unsigned char]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_uninitialized.h:373:37,
inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>]'
at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_vector.h:603:31,
inlined from 'frame_t::frame_t(const frame_t&)' at testcase.cpp:7:8,
inlined from 'virtual frame_t frame_filter_t::get()' at testcase.cpp:25:14:
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_algobase.h:399:17:
warning: array subscript 0 is outside array bounds of 'unsigned char [0]'
[-Warray-bounds=]
399 | { *__to = *__from; }
| ~~~~~~^~~~~~~~~
In file included from
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/allocator.h:46,
from
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/vector:63:
In member function '_Tp* std::__new_allocator<_Tp>::allocate(size_type, const
void*) [with _Tp = unsigned char]',
inlined from 'static _Tp* std::allocator_traits<std::allocator<_Tp1>
>::allocate(allocator_type&, size_type) [with _Tp = unsigned char]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/alloc_traits.h:475:28,
inlined from '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
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_vector.h:377:33,
inlined from 'void std::_Vector_base<_Tp,
_Alloc>::_M_create_storage(std::size_t) [with _Tp = unsigned char; _Alloc =
std::allocator<unsigned char>]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_vector.h:395:44,
inlined from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t,
const allocator_type&) [with _Tp = unsigned char; _Alloc =
std::allocator<unsigned char>]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_vector.h:331:26,
inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>]'
at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/stl_vector.h:600:61,
inlined from 'frame_t::frame_t(const frame_t&)' at testcase.cpp:7:8,
inlined from 'virtual frame_t frame_filter_t::get()' at testcase.cpp:25:14:
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:151:55:
note: object of size 0 allocated by 'operator new'
151 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
| ^
I think these warnings might be bogus, since it seems to be complaining about
copying an empty std::vector<uint8_t> here?
It might also get confused due to the padding inserted between the
frame_t::pts_ and frame_t::timescale_ members, since if you remove either of
these members, the warning goes away.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
@ 2024-01-04 21:10 ` pinskia at gcc dot gnu.org
2024-01-06 22:49 ` dimitry@unified-streaming.com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-04 21:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So I suspect it is either inlining differences due to slightly increased sizes
in some cases or jump threading due to the extra check. I highly doubt that
patch is underlying cause of the warning ...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
2024-01-04 21:10 ` [Bug tree-optimization/113239] " pinskia at gcc dot gnu.org
@ 2024-01-06 22:49 ` dimitry@unified-streaming.com
2024-01-06 22:53 ` dimitry@unified-streaming.com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dimitry@unified-streaming.com @ 2024-01-06 22:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
Dimitry Andric <dimitry@unified-streaming.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #2 from Dimitry Andric <dimitry@unified-streaming.com> ---
I reduced a preprocessed version of the test case to a more minimal version,
which does not include the full <vector> header. Bisecting with the
preprocessed and reduced test case again shows that it regressed with commit
e7310e24b1c0ca67b1bb507c1330b2bf39e59e32 ("Make ranger vrp1 default").
New test case:
// g++ -std=c++17 -Wall -O2 -c pr113239-preproc.cpp
struct __is_move_iterator
{
enum
{
__value
};
};
template <typename _Iterator, typename> struct __normal_iterator
{
_Iterator _M_current;
__normal_iterator (_Iterator __i) : _M_current (__i) {}
_Iterator
base ()
{
return _M_current;
}
};
template <typename _Iterator, typename _Container>
bool
operator== (__normal_iterator<_Iterator, _Container> __lhs,
__normal_iterator<_Iterator, _Container> __rhs)
{
return __lhs.base () == __rhs.base ();
}
template <typename _Iterator, typename _Container>
_Iterator __niter_base (__normal_iterator<_Iterator, _Container>);
struct __copy_move
{
template <typename _Tp, typename _Up>
static void
__assign_one (_Tp __to, _Up __from)
{
*__to = *__from;
}
template <typename _Tp, typename _Up>
static _Up *
__copy_m (_Tp *__last, _Up *__result)
{
_Tp __first;
long _Num = __last - &__first;
__assign_one (__result, &__first);
return __result + _Num;
}
};
template <int, typename _II, typename _OI>
_OI
__copy_move_a2 (_II __last, _OI __result)
{
return __copy_move::__copy_m (__last, __result);
}
template <int _IsMove, typename _II, typename _OI>
_OI
__copy_move_a1 (_II __last, _OI __result)
{
return __copy_move_a2<_IsMove> (__last, __result);
}
template <int _IsMove, typename _II, typename _OI>
_OI
__copy_move_a (_II __last, _OI __result)
{
_OI __trans_tmp_1
= __copy_move_a1<_IsMove> (__niter_base (__last), __result);
return __trans_tmp_1;
}
template <typename _II, typename _OI>
void
copy (_II __last, _OI __result)
{
__copy_move_a<__is_move_iterator::__value> (__last, __result);
}
template <typename _Tp> struct __new_allocator
{
# 125
"/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h"
3
unsigned char *
allocate (long __n)
{
if (alignof (char))
std::align_val_t __al ((sizeof (_Tp), __al));
return static_cast<unsigned char *> (operator new (__n));
}
};
template <typename> struct allocator_traits;
template <typename _Tp> struct allocator_traits<__new_allocator<_Tp> >
{
using allocator_type = __new_allocator<_Tp>;
using pointer = _Tp *;
using const_pointer = _Tp *;
using size_type = long;
template <typename _Up> using rebind_alloc = __new_allocator<_Up>;
static pointer
allocate (allocator_type __a, size_type __n)
{
return __a.allocate (__n);
}
};
struct __alloc_traits : allocator_traits<__new_allocator<unsigned char> >
{
struct rebind
{
typedef rebind_alloc<unsigned char> other;
};
};
struct __uninitialized_copy
{
template <typename _InputIterator, typename _ForwardIterator>
static __uninit_copy (_InputIterator __last, _ForwardIterator __result)
{
copy (__last, __result);
}
};
template <typename _InputIterator, typename _ForwardIterator>
uninitialized_copy (_InputIterator __last, _ForwardIterator __result)
{
__uninitialized_copy::__uninit_copy (__last, __result);
}
template <typename _InputIterator, typename _ForwardIterator, typename _Tp>
__uninitialized_copy_a (_InputIterator, _InputIterator __last,
_ForwardIterator __result, _Tp)
{
uninitialized_copy (__last, __result);
}
struct _Vector_base
{
typedef __alloc_traits::rebind::other _Tp_alloc_type;
typedef __alloc_traits::pointer pointer;
struct _Vector_impl_data
{
pointer _M_start;
pointer _M_finish;
};
struct _Vector_impl : _Tp_alloc_type, _Vector_impl_data
{
_Vector_impl (_Tp_alloc_type);
};
_Vector_base (long __n, __new_allocator<unsigned char> __a) : _M_impl (__a)
{
_M_impl._M_start = _M_allocate (__n);
}
_Vector_impl _M_impl;
pointer
_M_allocate (unsigned long __n)
{
return __n ? __alloc_traits::allocate (_M_impl, __n) : pointer ();
}
};
struct vector : _Vector_base
{
typedef __normal_iterator<__alloc_traits::const_pointer, int> const_iterator;
vector ();
_Tp_alloc_type __trans_tmp_5;
vector (vector &__x) : _Vector_base (__x.size (), __trans_tmp_5)
{
_Tp_alloc_type __trans_tmp_4;
const_iterator __trans_tmp_2 = 0, __trans_tmp_3 = 0;
__uninitialized_copy_a (__trans_tmp_2, __trans_tmp_3, _M_impl._M_start,
__trans_tmp_4);
}
const_iterator
begin ()
{
return _M_impl._M_start;
}
const_iterator
end ()
{
return _M_impl._M_finish;
}
size () { return _M_impl._M_finish - _M_impl._M_start; }
empty () { return begin () == end (); }
};
struct frame_t
{
frame_t () : pts_ (0), timescale_ (0), data_ () {}
long pts_;
int timescale_;
vector data_;
};
struct frame_source_t
{
virtual frame_t get ();
};
struct frame_filter_t : frame_source_t
{
frame_t
get ()
{
if (current_frame_.data_.empty ())
return current_frame_;
}
frame_t current_frame_;
};
create_frame_filter () { frame_filter_t (); }
// EOT
With gcc-13-3595-g7b1cdca6d6d:
$ ~/ins/gcc-13-3595-g7b1cdca6d6d/bin/g++ -std=c++17 -O2 -Wall -Werror -c
pr113239-preproc.cpp
(no warning)
With gcc-13-3596-ge7310e24b1c/bin/g++:
$ ~/ins/gcc-13-3596-ge7310e24b1c/bin/g++ -std=c++17 -O2 -Wall -Werror -c
pr113239-preproc.cpp
In static member function 'static void __copy_move::__assign_one(_Tp, _Up)
[with _Tp = unsigned char*; _Up = unsigned char*]',
inlined from 'static _Up* __copy_move::__copy_m(_Tp*, _Up*) [with _Tp =
unsigned char; _Up = unsigned char]' at pr113239-preproc.cpp:41:18,
inlined from '_OI __copy_move_a2(_II, _OI) [with int <anonymous> = 0; _II =
unsigned char*; _OI = unsigned char*]' at pr113239-preproc.cpp:49:32,
inlined from '_OI __copy_move_a1(_II, _OI) [with int _IsMove = 0; _II =
unsigned char*; _OI = unsigned char*]' at pr113239-preproc.cpp:55:34,
inlined from '_OI __copy_move_a(_II, _OI) [with int _IsMove = 0; _II =
__normal_iterator<unsigned char*, int>; _OI = unsigned char*]' at
pr113239-preproc.cpp:62:33,
inlined from 'void copy(_II, _OI) [with _II = __normal_iterator<unsigned
char*, int>; _OI = unsigned char*]' at pr113239-preproc.cpp:69:46,
inlined from 'static int
__uninitialized_copy::__uninit_copy(_InputIterator, _ForwardIterator) [with
_InputIterator = __normal_iterator<unsigned char*, int>; _ForwardIterator =
unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:162:10,
inlined from 'int uninitialized_copy(_InputIterator, _ForwardIterator)
[with _InputIterator = __normal_iterator<unsigned char*, int>; _ForwardIterator
= unsigned char*]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:168:39,
inlined from 'int __uninitialized_copy_a(_InputIterator, _InputIterator,
_ForwardIterator, _Tp) [with _InputIterator = __normal_iterator<unsigned char*,
int>; _ForwardIterator = unsigned char*; _Tp = __new_allocator<unsigned char>]'
at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:174:22,
inlined from 'vector::vector(vector&)' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:209:28,
inlined from 'frame_t::frame_t(frame_t&)' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:225:8,
inlined from 'virtual frame_t frame_filter_t::get()' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:242:14:
pr113239-preproc.cpp:33:11: error: array subscript 0 is outside array bounds of
'unsigned char [0]' [-Werror=array-bounds]
33 | *__to = *__from;
| ~~~~~~^~~~~~~~~
In member function 'unsigned char* __new_allocator<_Tp>::allocate(long int)
[with _Tp = unsigned char]',
inlined from 'static _Tp* allocator_traits<__new_allocator<_Tp>
>::allocate(allocator_type, size_type) [with _Tp = unsigned char]' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:147:25,
inlined from 'unsigned char* _Vector_base::_M_allocate(long unsigned int)'
at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:197:43,
inlined from '_Vector_base::_Vector_base(long int, __new_allocator<unsigned
char>)' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:191:36,
inlined from 'vector::vector(vector&)' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:205:66,
inlined from 'frame_t::frame_t(frame_t&)' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:225:8,
inlined from 'virtual frame_t frame_filter_t::get()' at
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:242:14:
/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocator.h:133:55:
note: object of size 0 allocated by 'operator new'
133 |
| ^
cc1plus: all warnings being treated as errors
So there seems to be some problem in the "ranger" vrp1 pass. I'm CC'ing the
author of that commit.
I could try to use --param=vrp1-mode=vrp to see if that makes the warning go
away... :)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
2024-01-04 21:10 ` [Bug tree-optimization/113239] " pinskia at gcc dot gnu.org
2024-01-06 22:49 ` dimitry@unified-streaming.com
@ 2024-01-06 22:53 ` dimitry@unified-streaming.com
2024-01-08 14:57 ` [Bug tree-optimization/113239] [13/14 " rguenth at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dimitry@unified-streaming.com @ 2024-01-06 22:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #3 from Dimitry Andric <dimitry@unified-streaming.com> ---
Alright, I can confirm that adding --param=vrp1-mode=vrp makes the warning go
away. However, this option is no longer recognized by gcc-14-6924-g00dea7e8c41.
I assume the ranger mode is now the default, and the older mode is no longer
supported.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (2 preceding siblings ...)
2024-01-06 22:53 ` dimitry@unified-streaming.com
@ 2024-01-08 14:57 ` rguenth at gcc dot gnu.org
2024-01-21 1:44 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-08 14:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[13 regression] After |[13/14 regression] After
|822a11a1e64, bogus |822a11a1e64, bogus
|-Warray-bounds warnings in |-Warray-bounds warnings in
|std::vector |std::vector
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2024-01-08
Target Milestone|--- |13.3
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (3 preceding siblings ...)
2024-01-08 14:57 ` [Bug tree-optimization/113239] [13/14 " rguenth at gcc dot gnu.org
@ 2024-01-21 1:44 ` pinskia at gcc dot gnu.org
2024-01-21 1:46 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-21 1:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the missed optimization was there in GCC 12, just the diagnostic was not.
We have:
```
_4 = MEM[(const unsigned char * const &)current_frame__2(D) + 24];
_7 = MEM[(const unsigned char * const &)current_frame__2(D) + 16];
if (_4 == _7)
goto <bb 3>; [17.43%]
else
goto <bb 6>; [82.57%]
<bb 3> [local count: 187153200]:
...
MEM <vector(2) long unsigned int> [(unsigned char * *)_5(D) + 16B] = { 0, 0
};
MEM[(struct _Vector_base *)_5(D) + 16B]._M_impl.D.21112._M_end_of_storage =
0B;
_21 = MEM[(const unsigned char * const &)current_frame__2(D) + 24];
_22 = MEM[(const unsigned char * const &)current_frame__2(D) + 16];
_Num_23 = _21 - _22;
```
But based on the original condition (and the stores to offset of _5 [which
technically cannot alias current_frame__2]), _Num_23 will be 0.
What g:822a11a1e642e0abe92a996e7033a5066905a447 does is just add an extra if
statement where we get:
```
if (_Num_24 > 1)
goto <bb 4>; [90.00%]
else
goto <bb 5>; [10.00%]
<bb 4> [local count: 156478790]:
_Num.5_28 = (long unsigned int) _Num_24;
__builtin_memmove (0B, _22, _Num.5_28);
goto <bb 7>; [100.00%]
<bb 5> [local count: 17386533]:
if (_Num_24 == 1)
goto <bb 6>; [34.00%]
else
goto <bb 7>; [66.00%]
<bb 6> [local count: 5911421]:
MEM[(unsigned char *)0B] ={v} 0; /// <<<<<< This is causing the warning
__builtin_trap ();
```
Instead of just:
```
if (_Num_23 != 0)
goto <bb 4>; [33.00%]
else
goto <bb 5>; [67.00%]
<bb 4> [local count: 57375556]:
_Num.4_24 = (long unsigned int) _Num_23;
__builtin_memmove (0B, _22, _Num.4_24);
```
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (4 preceding siblings ...)
2024-01-21 1:44 ` pinskia at gcc dot gnu.org
@ 2024-01-21 1:46 ` pinskia at gcc dot gnu.org
2024-01-22 16:05 ` fche at redhat dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-21 1:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Why the warning only happens with the 2 elements in frame_t, I have no idea
really since there seems not to be any changes in the final IR (except for an
extra load/store for those 2 elements).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (5 preceding siblings ...)
2024-01-21 1:46 ` pinskia at gcc dot gnu.org
@ 2024-01-22 16:05 ` fche at redhat dot com
2024-01-22 16:34 ` dimitry@unified-streaming.com
2024-03-07 20:52 ` law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: fche at redhat dot com @ 2024-01-22 16:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #7 from Frank Ch. Eigler <fche at redhat dot com> ---
Wonder if this similar but different diagnostic is closely related:
https://kojipkgs.fedoraproject.org//work/tasks/6259/112176259/build.log
[...]
inlined from ‘mutatee::instrument_dynprobe_target(BPatch_object*,
dynprobe_target const&)’ at mutatee.cxx:444:22:
/usr/include/c++/14/bits/stl_algobase.h:438:30: error: ‘memmove’ writing
between 9 and 9223372036854775800 bytes into a region of size 0 overflows the
destination [-Werror=stringop-overflow=]
438 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/usr/include/c++/14/x86_64-redhat-linux/bits/c++allocator.h:33,
from /usr/include/c++/14/bits/allocator.h:46,
from /usr/include/c++/14/string:43:
In member function ‘std::__new_allocator<BPatch_snippet*>::allocate(unsigned
long, void const*)’,
[...]
where the c++ code in question is a straight
vector<> foo;
vector<> bar;
foo.insert(foo.end(), bar.begin(), bar.end());
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (6 preceding siblings ...)
2024-01-22 16:05 ` fche at redhat dot com
@ 2024-01-22 16:34 ` dimitry@unified-streaming.com
2024-03-07 20:52 ` law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: dimitry@unified-streaming.com @ 2024-01-22 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
--- Comment #8 from Dimitry Andric <dimitry@unified-streaming.com> ---
(In reply to Frank Ch. Eigler from comment #7)
> Wonder if this similar but different diagnostic is closely related:
...
> where the c++ code in question is a straight
>
> vector<> foo;
> vector<> bar;
> foo.insert(foo.end(), bar.begin(), bar.end());
I can't reproduce the warning here with a vector<int> example, the function is
entirely optimized away too. But even if I return the result, e.g.:
std::vector<int> f(std::vector<int> bar)
{
std::vector<int> foo;
foo.insert(foo.end(), bar.begin(), bar.end());
return foo;
}
still no warning. But I think you might need to reduce the mutatee.cxx case.
That said, the warning you show is triggered in a different place, and the
"between 9 and 9223372036854775800 bytes" is also different.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/113239] [13/14 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
` (7 preceding siblings ...)
2024-01-22 16:34 ` dimitry@unified-streaming.com
@ 2024-03-07 20:52 ` law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 20:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu.org
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-03-07 20:52 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 20:45 [Bug c++/113239] New: [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector dimitry@unified-streaming.com
2024-01-04 21:10 ` [Bug tree-optimization/113239] " pinskia at gcc dot gnu.org
2024-01-06 22:49 ` dimitry@unified-streaming.com
2024-01-06 22:53 ` dimitry@unified-streaming.com
2024-01-08 14:57 ` [Bug tree-optimization/113239] [13/14 " rguenth at gcc dot gnu.org
2024-01-21 1:44 ` pinskia at gcc dot gnu.org
2024-01-21 1:46 ` pinskia at gcc dot gnu.org
2024-01-22 16:05 ` fche at redhat dot com
2024-01-22 16:34 ` dimitry@unified-streaming.com
2024-03-07 20:52 ` law 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).