https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113239
Dimitry Andric <dimi...@unified-streaming.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #2 from Dimitry Andric <dimi...@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... :)