https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91462
Bug ID: 91462 Summary: missing -Warray-bounds writing to an empty flexible array member in a ctor Product: gcc Version: 9.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: --- In the test case below, the write to the empty flexible array member in Ax isn't diagnosed even though the equivalent write in A0 is. $ cat t.C && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.C struct A0 { char n, a[0]; A0 () { a[0] = 0; } // -Warray-bounds (good) }; void f (void*); void g () { struct A0 a; f (&a); } struct Ax { char n, a[]; Ax () { a[0] = 0; } // missing -Warray-bounds }; void h () { struct Ax a; f (&a); } t.C: In function ‘void g()’: t.C:5:14: warning: array subscript 0 is above array bounds of ‘char [0]’ [-Warray-bounds] 5 | A0 () { a[0] = 0; } | ~~~^ ;; Function g (_Z1gv, funcdef_no=3, decl_uid=2317, cgraph_uid=4, symbol_order=3) g () { struct A0 a; <bb 2> [local count: 1073741824]: a ={v} {CLOBBER}; a.a[0] = 0; f (&a); a ={v} {CLOBBER}; return; } ;; Function h (_Z1hv, funcdef_no=7, decl_uid=2362, cgraph_uid=8, symbol_order=7) h () { struct Ax a; <bb 2> [local count: 1073741824]: a ={v} {CLOBBER}; a.a[0] = 0; f (&a); a ={v} {CLOBBER}; return; }