public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter @ 2020-10-14 17:22 msebor at gcc dot gnu.org 2020-10-14 17:46 ` [Bug middle-end/97425] " msebor at gcc dot gnu.org 2021-09-26 7:54 ` pinskia at gcc dot gnu.org 0 siblings, 2 replies; 3+ messages in thread From: msebor at gcc dot gnu.org @ 2020-10-14 17:22 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97425 Bug ID: 97425 Summary: bogus array bounds in -Warray-bounds for a function array parameter Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Wartray-bounds warnings in the test case below are all expected but the bounds of the array types referenced in the messages for f3 and and f4 don't correspond to those in the array parameters. In f3 the warning should mention ‘int[2][3][4]’ instead and in f4 it should reference ‘int[1][2][3][4]’. $ cat z.c && gcc -O2 -S -Wall z.c void f1 (int a[4]) { int *p = &a[0]; p[4] = 0; } void f2 (int a[3][4]) { int *p = &a[0][0]; p[3 * 4] = 0; } void f3 (int a[2][3][4]) { int *p = &a[0][0][0]; p[2 * 3 * 4] = 0; } void f4 (int a[1][2][3][4]) { int *p = &a[0][0][0][0]; p[1 * 2 * 3 * 4] = 0; } z.c: In function ‘f1’: z.c:4:4: warning: array subscript 4 is outside array bounds of ‘int[4]’ [-Warray-bounds] 4 | p[4] = 0; | ~^~~ z.c:1:14: note: while referencing ‘a’ 1 | void f1 (int a[4]) | ~~~~^~~~ z.c: In function ‘f2’: z.c:10:4: warning: array subscript 12 is outside array bounds of ‘int[3]’ [-Warray-bounds] 10 | p[3 * 4] = 0; | ~^~~~~~~ z.c:7:14: note: while referencing ‘a’ 7 | void f2 (int a[3][4]) | ~~~~^~~~~~~ z.c: In function ‘f3’: z.c:16:4: warning: array subscript 24 is outside array bounds of ‘int[2][4]’ [-Warray-bounds] 16 | p[2 * 3 * 4] = 0; | ~^~~~~~~~~~~ z.c:13:14: note: while referencing ‘a’ 13 | void f3 (int a[2][3][4]) | ~~~~^~~~~~~~~~ z.c: In function ‘f4’: z.c:16:16: warning: array subscript 24 is outside array bounds of ‘int[1][3][4]’ [-Warray-bounds] 16 | p[2 * 3 * 4] = 0; | ~~~~~~~~~~~~~^~~ z.c:19:14: note: while referencing ‘a’ 19 | void f4 (int a[1][2][3][4]) | ~~~~^~~~~~~~~~~~~ ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/97425] bogus array bounds in -Warray-bounds for a function array parameter 2020-10-14 17:22 [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter msebor at gcc dot gnu.org @ 2020-10-14 17:46 ` msebor at gcc dot gnu.org 2021-09-26 7:54 ` pinskia at gcc dot gnu.org 1 sibling, 0 replies; 3+ messages in thread From: msebor at gcc dot gnu.org @ 2020-10-14 17:46 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97425 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- 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=/dev/stdout z.c void f (void) { extern int a[2][3][4]; a[2][0][0] = 0; // correct subscript } void g (int a[2][3][4]) { a[2][0][0] = 0; // wrong subscript } void h (int (*p)[2][3][4]) { (*p)[2][0][0] = 0; // correct subscript } ;; Function f (f, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=0) ;; 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 ‘f’: z.c:4:4: warning: array subscript 2 is above array bounds of ‘int[2][3][4]’ [-Warray-bounds] 4 | a[2][0][0] = 0; // correct subscript (2) | ~^~~ z.c:3:14: note: while referencing ‘a’ 3 | extern int a[2][3][4]; | ^ f () { <bb 2> [local count: 1073741824]: a[2][0][0] = 0; return; } ;; Function g (g, funcdef_no=1, decl_uid=1936, cgraph_uid=2, symbol_order=1) ;; 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 ‘g’: z.c:9:4: warning: array subscript 24 is outside array bounds of ‘int[2][4]’ [-Warray-bounds] 9 | a[2][0][0] = 0; // wrong subscript (24) | ~^~~ z.c:7:13: note: while referencing ‘a’ 7 | void g (int a[2][3][4]) | ~~~~^~~~~~~~~~ g (int[3][4] * a) { <bb 2> [local count: 1073741824]: MEM[(int[3][4] *)a_1(D) + 96B][0][0] = 0; return; } ;; Function h (h, funcdef_no=2, decl_uid=1939, cgraph_uid=3, symbol_order=2) ;; 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 ‘h’: z.c:14:7: warning: array subscript 2 is above array bounds of ‘int[2][3][4]’ [-Warray-bounds] 14 | (*p)[2][0][0] = 0; // correct subscript (2) | ~~~~^~~ z.c:12:15: note: while referencing ‘p’ 12 | void h (int (*p)[2][3][4]) | ~~~~~~^~~~~~~~~~~ h (int[2][3][4] * p) { <bb 2> [local count: 1073741824]: (*p_2(D))[2][0][0] = 0; return; } ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/97425] bogus array bounds in -Warray-bounds for a function array parameter 2020-10-14 17:22 [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter msebor at gcc dot gnu.org 2020-10-14 17:46 ` [Bug middle-end/97425] " msebor at gcc dot gnu.org @ 2021-09-26 7:54 ` pinskia at gcc dot gnu.org 1 sibling, 0 replies; 3+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-09-26 7:54 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97425 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-09-26 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-26 7:54 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-10-14 17:22 [Bug middle-end/97425] New: bogus array bounds in -Warray-bounds for a function array parameter msebor at gcc dot gnu.org 2020-10-14 17:46 ` [Bug middle-end/97425] " msebor at gcc dot gnu.org 2021-09-26 7:54 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).