From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 56C8B384A880; Mon, 22 Apr 2024 20:16:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56C8B384A880 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713816960; bh=dZ78sag6mFei8EJAVTKD7g+W4TlPfsAbqox5kZxAc6U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bZ5GswtZT3ZcUG0aTSaGeGGnpIBeo8ag8uIrRdrcMy9IMVQKWYTCxoe4SMkLIev3b BOj0d85ZXOe2gMIZhh8Td4QSjokKjCWoUXqw23oY3FIXsv6PwlEajV9QHxp7MKl1gJ C/pu/GtBJt2UiB7RgZ2GTiF2fxXDPIOTptOJxKPg= From: "kees at outflux dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109071] -Warray-bounds false positive warnings due to code duplication from jump threading Date: Mon, 22 Apr 2024 20:15:59 +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.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: kees at outflux dot net X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: qinzhao 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=3D109071 --- Comment #8 from Kees Cook --- The warning is about: val =3D &sg->vals[index]; poc.c:20:20: warning: array subscript 4 is above array bounds of 'int[4]' [-Warray-bounds=3D] 20 | val =3D &sg->vals[index]; | ~~~~~~~~^~~~~~~ which happens before the warn(). And if the check is moved out of the "assign()" function, the warning goes away: val =3D &sg->vals[index]; if (index >=3D MAX_ENTRIES) warn(); assign(0, ptr, index); assign(*val, ptr, index); Normally -Warray-bounds doesn't warn when a value is totally unknown (i.e. "index" here can be [-INT_MAX,INT_MAX]). Why does the warning change when t= he MAX_ENTRIES test is moved inside assign()?=