From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1E04A3858C3A; Thu, 9 May 2024 16:29:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E04A3858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715272175; bh=94ky+/mS3JLZAMDDei7znke9YQl05hN245q8ZO/F//I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FZjYFMqPAR5VNA5ai3L2IypwXl1FSTDcY1Jl69dq/BzB8Rh7JfsjRi7/EoOV/Plgv Y4PPRw3Vtb18Rf/6NaR52XI2VtiLJjVoxo3FPwhtgDTgijwhSJrB9bZ9+aT5b0iAPH QlbKTQwyEKYA4WKmpPMdWBGlID+H1fSj5Ev5EFKE= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115005] [gcc-13] bogus -Warray-bounds warning Date: Thu, 09 May 2024 16:29:34 +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: 13.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: 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=3D115005 --- Comment #2 from Andrew Pinski --- Folding statement: _336 =3D cmd_8bits[numbits_181]; Folded into: _336 =3D cmd_8bits[4294967295]; Which comes from: uint32 d =3D get_bits(in, numbits+1, &bb); if (d >=3D cmd_8bits[numbits]) { get_bits: static uint32 get_bits(HIO_HANDLE *f, int n, struct bit_buffer *bb) { uint32 bits; if (n =3D=3D 0) { return 0; } There is a jump threading there handling n=3D=3D0 (aka numbits=3D=3D-1u) an= d that is causing the warning. Now if I understand it numbits can't be more than 128 = (or even 16 in the 16bit case). Adding `if (numbits >=3D 128) __builtin_unreachable();` right before the gi= t_bits gets rid of the warning and seems like would produce better code. The reason why using smaller types works is well (numbits+1) can never be 0= .=