From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B1942384A87E; Mon, 20 Apr 2020 22:16:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1942384A87E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587420993; bh=Q2Do3TOwDnT6u8Jd4p7CTM0UkekSAINpCTAr41YJUWg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=n6g5EtTqmZFwYeMK/3SwWyJH/VrstBEJEBsOI44liSXxQLTtsrr+p+82xd3plr1Ls kgzTnsGAVYsaCIAeT5Wtp3mzrbQWz7zxPBsmqUchHg/dNajj+ZafDpRJrx/g6CTbN2 Sv7ZmIO51QpAjgcCZPlGVDG19UqrKyK1KeMKPOj8= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94675] [9 regression] -Warray-bounds false positive with -O2 Date: Mon, 20 Apr 2020 22:16:33 +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: unknown 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: 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: Mon, 20 Apr 2020 22:16:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94675 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #1 from Martin Sebor --- The false positive is not due a shortcoming of the warning but rather due to GCC not having a sufficiently sophisticated analysis of relationships of pointers into the same objects. The same warning (and probably a numbers as well) can be reproduced with a simpler example. $ cat pr94675.c && gcc -O2 -S -Wall -fdump-tree-vrp=3D/dev/stdout pr94675.c unsigned char c, n; int f (void) { if (n <=3D 7) return 0; unsigned char *p =3D &c, *q =3D p + n; if (q - p <=3D 7) // not eliminated return 0; return p[7]; // spurious -Warray-bounds } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1932, cgraph_uid=3D1, symbol_o= rder=3D2) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 4 ;; 2 succs { 4 3 } ;; 3 succs { 4 } ;; 4 succs { 1 } Value ranges after VRP: n.0_1: unsigned char VARYING _2: unsigned char VARYING _3: int [0, 255] _5: int [0, 255] pr94675.c: In function =E2=80=98f=E2=80=99: pr94675.c:12:11: warning: array subscript 7 is outside array bounds of =E2=80=98unsigned char[1]=E2=80=99 [-Warray-bounds] 12 | return p[7]; | ~^~~ pr94675.c:1:15: note: while referencing =E2=80=98c=E2=80=99 1 | unsigned char c, n; | ^ f () { unsigned char n.0_1; unsigned char _2; int _3; int _5; [local count: 1073741824]: n.0_1 =3D n; if (n.0_1 <=3D 7) goto ; [34.00%] else goto ; [66.00%] [local count: 708669601]: _2 =3D MEM[(unsigned char *)&c + 7B]; _5 =3D (int) _2; [local count: 1073741824]: # _3 =3D PHI <0(2), _5(3)> return _3; } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1932, cgraph_uid=3D1, symbol_o= rder=3D2) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 4 ;; 2 succs { 4 3 } ;; 3 succs { 4 } ;; 4 succs { 1 } Value ranges after VRP: n.0_1: unsigned char VARYING _2: unsigned char VARYING _3: int [0, 255] _5: int [0, 255] f () { unsigned char n.0_1; unsigned char _2; int _3; int _5; [local count: 1073741824]: n.0_1 =3D n; if (n.0_1 <=3D 7) goto ; [34.00%] else goto ; [66.00%] [local count: 708669601]: _2 =3D MEM[(unsigned char *)&c + 7B]; _5 =3D (int) _2; [local count: 1073741824]: # _3 =3D PHI <_5(3), 0(2)> return _3; }=