From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B6FF83858D35; Sat, 6 Jan 2024 22:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6FF83858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704581393; bh=eVwhfN3IvXvLyx0KfEUzd78H4Sj68dXxeOABFCmO2sI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t8jvSMPwTo9grdviNvpPrXUWWth2rFovEgDrmVVrjk7MSwttTli3PijXdXgK3Jl9p n4oSUPuxEwc93zWxA8fo3ATGSU/m9GiIGka45ajB4Ca9p0SbbuAvhTxrwxSBs2T6yO TG25otllDxwdceD3YDkJRHw8yon58/zhc47HZjxM= From: "dimitry@unified-streaming.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113239] [13 regression] After 822a11a1e64, bogus -Warray-bounds warnings in std::vector Date: Sat, 06 Jan 2024 22:49:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: dimitry@unified-streaming.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113239 Dimitry Andric changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #2 from Dimitry Andric --- I reduced a preprocessed version of the test case to a more minimal version, which does not include the full 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=3Dc++17 -Wall -O2 -c pr113239-preproc.cpp struct __is_move_iterator { enum { __value }; }; template struct __normal_iterator { _Iterator _M_current; __normal_iterator (_Iterator __i) : _M_current (__i) {} _Iterator base () { return _M_current; } }; template bool operator=3D=3D (__normal_iterator<_Iterator, _Container> __lhs, __normal_iterator<_Iterator, _Container> __rhs) { return __lhs.base () =3D=3D __rhs.base (); } template _Iterator __niter_base (__normal_iterator<_Iterator, _Container>); struct __copy_move { template static void __assign_one (_Tp __to, _Up __from) { *__to =3D *__from; } template static _Up * __copy_m (_Tp *__last, _Up *__result) { _Tp __first; long _Num =3D __last - &__first; __assign_one (__result, &__first); return __result + _Num; } }; template _OI __copy_move_a2 (_II __last, _OI __result) { return __copy_move::__copy_m (__last, __result); } template _OI __copy_move_a1 (_II __last, _OI __result) { return __copy_move_a2<_IsMove> (__last, __result); } template _OI __copy_move_a (_II __last, _OI __result) { _OI __trans_tmp_1 =3D __copy_move_a1<_IsMove> (__niter_base (__last), __result); return __trans_tmp_1; } template void copy (_II __last, _OI __result) { __copy_move_a<__is_move_iterator::__value> (__last, __result); } template struct __new_allocator { # 125 "/home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocat= or.h" 3 unsigned char * allocate (long __n) { if (alignof (char)) std::align_val_t __al ((sizeof (_Tp), __al)); return static_cast (operator new (__n)); } }; template struct allocator_traits; template struct allocator_traits<__new_allocator<_Tp> > { using allocator_type =3D __new_allocator<_Tp>; using pointer =3D _Tp *; using const_pointer =3D _Tp *; using size_type =3D long; template using rebind_alloc =3D __new_allocator<_Up>; static pointer allocate (allocator_type __a, size_type __n) { return __a.allocate (__n); } }; struct __alloc_traits : allocator_traits<__new_allocator > { struct rebind { typedef rebind_alloc other; }; }; struct __uninitialized_copy { template static __uninit_copy (_InputIterator __last, _ForwardIterator __result) { copy (__last, __result); } }; template uninitialized_copy (_InputIterator __last, _ForwardIterator __result) { __uninitialized_copy::__uninit_copy (__last, __result); } template __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 __a) : _M_impl (__= a) { _M_impl._M_start =3D _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_itera= tor; 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 =3D 0, __trans_tmp_3 =3D 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 () =3D=3D 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=3Dc++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=3Dc++17 -O2 -Wall -Werror -c pr113239-preproc.cpp In static member function 'static void __copy_move::__assign_one(_Tp, _Up) [with _Tp =3D unsigned char*; _Up =3D unsigned char*]', inlined from 'static _Up* __copy_move::__copy_m(_Tp*, _Up*) [with _Tp = =3D unsigned char; _Up =3D unsigned char]' at pr113239-preproc.cpp:41:18, inlined from '_OI __copy_move_a2(_II, _OI) [with int =3D 0;= _II =3D unsigned char*; _OI =3D unsigned char*]' at pr113239-preproc.cpp:49:32, inlined from '_OI __copy_move_a1(_II, _OI) [with int _IsMove =3D 0; _II= =3D unsigned char*; _OI =3D unsigned char*]' at pr113239-preproc.cpp:55:34, inlined from '_OI __copy_move_a(_II, _OI) [with int _IsMove =3D 0; _II = =3D __normal_iterator; _OI =3D unsigned char*]' at pr113239-preproc.cpp:62:33, inlined from 'void copy(_II, _OI) [with _II =3D __normal_iterator; _OI =3D unsigned char*]' at pr113239-preproc.cpp:69:46, inlined from 'static int __uninitialized_copy::__uninit_copy(_InputIterator, _ForwardIterator) [with _InputIterator =3D __normal_iterator; _ForwardIterator= =3D unsigned char*]' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:162:10, inlined from 'int uninitialized_copy(_InputIterator, _ForwardIterator) [with _InputIterator =3D __normal_iterator; _ForwardIt= erator =3D unsigned char*]' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:168:39, inlined from 'int __uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, _Tp) [with _InputIterator =3D __normal_iterator; _ForwardIterator =3D unsigned char*; _Tp =3D __new_allocator]' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:174:22, inlined from 'vector::vector(vector&)' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.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_allocato= r.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_allocato= r.h:242:14: pr113239-preproc.cpp:33:11: error: array subscript 0 is outside array bound= s of 'unsigned char [0]' [-Werror=3Darray-bounds] 33 | *__to =3D *__from; | ~~~~~~^~~~~~~~~ In member function 'unsigned char* __new_allocator<_Tp>::allocate(long int) [with _Tp =3D unsigned char]', inlined from 'static _Tp* allocator_traits<__new_allocator<_Tp> >::allocate(allocator_type, size_type) [with _Tp =3D unsigned char]' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:147:25, inlined from 'unsigned char* _Vector_base::_M_allocate(long unsigned in= t)' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:197:43, inlined from '_Vector_base::_Vector_base(long int, __new_allocator)' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.h:191:36, inlined from 'vector::vector(vector&)' at /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.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_allocato= r.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_allocato= r.h:242:14: /home/dim/ins/gcc-14-6924-g00dea7e8c41/include/c++/14.0.0/bits/new_allocato= r.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=3Dvrp1-mode=3Dvrp to see if that makes the warni= ng go away... :)=