From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A247A385840D; Thu, 13 Jan 2022 22:52:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A247A385840D From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104017] New: unexpeted -Warray-bounds popping a fixed number of std::deque elements Date: Thu, 13 Jan 2022 22:52:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2022 22:52:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104017 Bug ID: 104017 Summary: unexpeted -Warray-bounds popping a fixed number of std::deque elements Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- I got the following report in my private mail. I file it here for reference (and my analysis). Although the warning isn't terribly informative I don't consider it a false positive. $ cat t.C && g++ -O2 -S -Wall t.C #include struct Node { Node const * parent =3D nullptr; }; void func(Node const * n) { std::deque p; Node const * e =3D n; while (e !=3D nullptr) { p.push_front(e); e =3D e->parent; } [[maybe_unused]] Node const * b; p.pop_front(); e =3D p.front(); p.pop_front(); b =3D p.back(); p.pop_back(); } In file included from /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-= gnu/bits/c++allocator.h:33, from /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/allocator.h= :46, from /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/deque:61, from t.C:1: In member function =E2=80=98void std::__new_allocator<_Tp>::destroy(_Up*) [= with _Up =3D const Node*; _Tp =3D const Node*]=E2=80=99, inlined from =E2=80=98static void std::allocator_traits >::destroy(allocator_type&, _Up*) [with _Up =3D const Node*; _Tp =3D const = Node*]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/alloc_trait= s.h:535:15, inlined from =E2=80=98void std::deque<_Tp, _Alloc>::pop_back() [with _T= p =3D const Node*; _Alloc =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :1604:28, inlined from =E2=80=98void func(const Node*)=E2=80=99 at t.C:22:15: /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/new_allocat= or.h:181:11: warning: array subscript -1 is outside array bounds of =E2=80=98const Node*= [64]=E2=80=99 [-Warray-bounds] 181 | { __p->~_Up(); } | ^~~ In member function =E2=80=98_Tp* std::__new_allocator<_Tp>::allocate(size_t= ype, const void*) [with _Tp =3D const Node*]=E2=80=99, inlined from =E2=80=98static _Tp* std::allocator_traits >::allocate(allocator_type&, size_type) [with _Tp =3D const Node*]=E2=80=99= at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/alloc_trait= s.h:464:28, inlined from =E2=80=98std::_Deque_base<_Tp, _Alloc>::_Ptr std::_Deque_b= ase<_Tp, _Alloc>::_M_allocate_node() [with _Tp =3D const Node*; _Alloc =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :583:26, inlined from =E2=80=98void std::_Deque_base<_Tp, _Alloc>::_M_create_nodes(_Map_pointer, _Map_pointer) [with _Tp =3D const No= de*; _Alloc =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :684:37, inlined from =E2=80=98void std::_Deque_base<_Tp, _Alloc>::_M_initialize_map(std::size_t) [with _Tp =3D const Node*; _Alloc = =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :658:19, inlined from =E2=80=98std::_Deque_base<_Tp, _Alloc>::_Deque_base() [wit= h _Tp =3D const Node*; _Alloc =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :460:26, inlined from =E2=80=98std::deque<_Tp, _Alloc>::deque() [with _Tp =3D co= nst Node*; _Alloc =3D std::allocator]=E2=80=99 at /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/stl_deque.h= :855:7, inlined from =E2=80=98void func(const Node*)=E2=80=99 at t.C:7:30: /build/gcc-master/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/new_allocat= or.h:137:55: note: at offset -8 into object of size 512 allocated by =E2=80=98operator n= ew=E2=80=99 137 | return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp))); | ^=