From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0427F3858034; Tue, 18 Jan 2022 11:12:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0427F3858034 From: "larsbj at gullik dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104017] unexpeted -Warray-bounds popping a fixed number of std::deque elements Date: Tue, 18 Jan 2022 11:12:01 +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: 9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: larsbj at gullik dot net 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 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: Tue, 18 Jan 2022 11:12:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104017 Lars Gullik Bj=C3=B8nnes changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |larsbj at gullik dot net --- Comment #2 from Lars Gullik Bj=C3=B8nnes --- (In reply to Martin Sebor from comment #1) ... > #include >=20 > struct Node { Node const * parent =3D nullptr; }; >=20 > void func(Node const * n) > { > std::deque p; >=20 > Node const * e =3D n; >=20 > while (e !=3D nullptr) { > p.push_front(e); > e =3D e->parent; > } >=20 > if (p.size ()) > p.pop_front(); > if (p.size ()) > p.pop_front(); > if (p.size ()) > p.pop_back(); > } >=20 >=20 > This test case also triggers a warning, for the same reason: GCC can't > determine the relationship between a deque's internal node pointers and t= he > result of std::deque::size() (which is a function of the node pointers). This is also the case amended with a check that the std::deque::size is lar= ge enough (for the same reason). In that case the crash can never happen, still GCC12 warns/errors. I agree that the first test case, and the warning from it, is helpful. Howe= ver this second one not so much.=