From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 915E03857C46; Wed, 14 Oct 2020 17:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 915E03857C46 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/97425] bogus array bounds in -Warray-bounds for a function array parameter Date: Wed, 14 Oct 2020 17:46:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: minor 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: 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: Wed, 14 Oct 2020 17:46:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97425 --- Comment #1 from Martin Sebor --- In addition to the bounds in the array type the subscript in some of the warnings issued for array parameters isn't right. $ cat z.c && gcc -O2 -S -Wall -fdump-tree-vrp1=3D/dev/stdout z.c void f (void) { extern int a[2][3][4]; a[2][0][0] =3D 0; // correct subscript } void g (int a[2][3][4]) {=20 a[2][0][0] =3D 0; // wrong subscript } void h (int (*p)[2][3][4]) { (*p)[2][0][0] =3D 0; // correct subscript } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1931, cgraph_uid=3D1, symbol_o= rder=3D0) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 ;; 2 succs { 1 } Value ranges after VRP: z.c: In function =E2=80=98f=E2=80=99: z.c:4:4: warning: array subscript 2 is above array bounds of =E2=80=98int[2= ][3][4]=E2=80=99 [-Warray-bounds] 4 | a[2][0][0] =3D 0; // correct subscript (2) | ~^~~ z.c:3:14: note: while referencing =E2=80=98a=E2=80=99 3 | extern int a[2][3][4]; | ^ f () { [local count: 1073741824]: a[2][0][0] =3D 0; return; } ;; Function g (g, funcdef_no=3D1, decl_uid=3D1936, cgraph_uid=3D2, symbol_o= rder=3D1) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 ;; 2 succs { 1 } Value ranges after VRP: z.c: In function =E2=80=98g=E2=80=99: z.c:9:4: warning: array subscript 24 is outside array bounds of =E2=80=98in= t[2][4]=E2=80=99 [-Warray-bounds] 9 | a[2][0][0] =3D 0; // wrong subscript (24) | ~^~~ z.c:7:13: note: while referencing =E2=80=98a=E2=80=99 7 | void g (int a[2][3][4]) | ~~~~^~~~~~~~~~ g (int[3][4] * a) { [local count: 1073741824]: MEM[(int[3][4] *)a_1(D) + 96B][0][0] =3D 0; return; } ;; Function h (h, funcdef_no=3D2, decl_uid=3D1939, cgraph_uid=3D3, symbol_o= rder=3D2) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 ;; 2 succs { 1 } Value ranges after VRP: z.c: In function =E2=80=98h=E2=80=99: z.c:14:7: warning: array subscript 2 is above array bounds of =E2=80=98int[= 2][3][4]=E2=80=99 [-Warray-bounds] 14 | (*p)[2][0][0] =3D 0; // correct subscript (2) | ~~~~^~~ z.c:12:15: note: while referencing =E2=80=98p=E2=80=99 12 | void h (int (*p)[2][3][4]) | ~~~~~~^~~~~~~~~~~ h (int[2][3][4] * p) { [local count: 1073741824]: (*p_2(D))[2][0][0] =3D 0; return; }=