From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BF28B3857C77; Sun, 14 Mar 2021 00:46:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF28B3857C77 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99580] False positive -Warray-bounds with -O2 Date: Sun, 14 Mar 2021 00:46:37 +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: 10.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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: keywords everconfirmed component cf_known_to_fail cc cf_reconfirmed_on blocked bug_status 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: Sun, 14 Mar 2021 00:46:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99580 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Ever confirmed|0 |1 Component|c++ |tree-optimization Known to fail| |10.2.0, 11.0, 7.3.0, 8.3.0, | |9.2.0 CC| |msebor at gcc dot gnu.org Last reconfirmed| |2021-03-14 Blocks| |56456 Status|UNCONFIRMED |NEW --- Comment #1 from Martin Sebor --- Confirmed. The warning first appeared with r238761 AKA "Teach VRP to regis= ter assertions along default switch labels (PR18046)." A simplified test case is below: $ cat pr99580.C && -O2 -S -Wall -fdump-tree-vrp1-details pr99580.C struct vec { int operator[] (int i) { switch (i) { default: case 0: return x; case 1: return y; case 2: return z; } } int x, y, z; }; vec v[3]; int f () { int max_el =3D v[0][1]; int max_j =3D 1; for (int i =3D 0; i < 3; i++) for (int j =3D i + 1; j < 3; j++) if (v[i][j] > max_el) max_j =3D j; return v[max_j][max_j]; } pr99580.C: In function =E2=80=98int f()=E2=80=99: pr99580.C:28:17: warning: array subscript 3 is above array bounds of =E2=80= =98vec [3]=E2=80=99 [-Warray-bounds] 28 | return v[max_j][max_j]; | ~~~~~~~^ pr99580.C:16:5: note: while referencing =E2=80=98v=E2=80=99 16 | vec v[3]; | ^ $ grep warning pr99580.C.110t.vrp1=20 Array bound warning for MEM [(struct vec *)&v][max_j_27] And: Simulating block 14 extract_range_from_stmt visiting: max_j_27 =3D ASSERT_EXPR = 1>; Intersecting int ~[1, 2] EQUIVALENCES: { max_j_21 } (1 elements) and int [1, 2147483646] to int [3, 2147483646] EQUIVALENCES: { max_j_21 } (1 elements) Intersecting int [3, 2147483646] EQUIVALENCES: { max_j_21 } (1 elements) and int VARYING to int [3, 2147483646] EQUIVALENCES: { max_j_21 } (1 elements) Found new range for max_j_27: int [3, 2147483646] EQUIVALENCES: { } (0 elements) Adding destination of edge (14 -> 17) to worklist Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds=