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]) | ~~~~^~~~~~~~~~~~~