https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95619
Bug ID: 95619 Summary: apparently in-bounds subscript in -Warray-bounds message Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- When the type of the access is obscured by a typedef (or macro, or, in C++, by a template parameter), -Warray-bounds warnings like the one below must be confusing. The warnings don't make it clear how "array subscript 2" can be "outside array bounds of ‘X[3]’ {aka ‘short int[3]’}". Either the warning should also mention the type of the access, maybe in the note, or perhaps better, the byte offset into the array (when the the types aren't the same). $ cat z.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout z.c typedef short X; typedef int Y; void f (void*); void g (void) { X a[3]; Y *p = (Y*)a; p[2] = 1; f (p); } z.c: In function ‘g’: z.c:10:4: warning: array subscript 2 is outside array bounds of ‘X[3]’ {aka ‘short int[3]’} [-Warray-bounds] 10 | p[2] = 1; | ~^~~ z.c:8:5: note: while referencing ‘a’ 8 | X a[3]; | ^ ;; Function g (g, funcdef_no=0, decl_uid=1935, cgraph_uid=1, symbol_order=0) g () { X a[3]; <bb 2> [local count: 1073741824]: MEM[(Y *)&a + 8B] = 1; f (&a); a ={v} {CLOBBER}; return; }