https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98483
Bug ID: 98483 Summary: missing -Warray-bounds for out of bounds accesses in system headers Product: gcc Version: 11.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: --- GCC warns for out-of-bounds accesses by inlined functions but not when they are defined in system headers, even if the function is inlined into (and the accessed object defined in) an ordinary, non-systen function. This is especially bad for C++ system libraries that are full of inline code. $ cat b.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout b.c # 1 "a.h" 1 3 4 # 2 "a.h" 3 4 static inline void f (int *p) { *p = 0; } # 1 "b.c" 1 static inline void g (int *p) { *p = 1; } int i[1]; void ff (void) { f (i + 1); // missing warning } void gg (void) { g (i + 1); // warning (good) } ;; Function ff (ff, funcdef_no=2, decl_uid=1950, cgraph_uid=3, symbol_order=3) void ff () { <bb 2> [local count: 1073741824]: MEM[(int *)&i + 4B] = 0; return; } In file included from a.h:7, from b.c:1: b.c: In function ‘gg’: b.c:4:6: warning: array subscript 1 is outside array bounds of ‘int[1]’ [-Warray-bounds] 4 | { | ^ b.c:7:5: note: while referencing ‘i’ 7 | | ^ ;; Function gg (gg, funcdef_no=3, decl_uid=1953, cgraph_uid=4, symbol_order=4) void gg () { <bb 2> [local count: 1073741824]: MEM[(int *)&i + 4B] = 1; return; }