https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97425
--- 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=/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 ()
{
[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)
{
[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)
{
[local count: 1073741824]:
(*p_2(D))[2][0][0] = 0;
return;
}