https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86613
Bug ID: 86613 Summary: missing -Warray-bounds on a wide string access due to ccp folding Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Similar to bug 86611 but with a different root cause, GCC fails to diagnose the out-of-bounds array index in the following test case, in both ilp32 and lp64. According to the dumps, the underlying root cause appears to be that the invalid array dereference is folded in ccp1. $ cat c.c && gcc -O2 -S -Warray-bounds -Wno-stringop-overflow -fdump-tree-objsz=/dev/stdout -fdump-tree-ccp1=/dev/stdout c.c -m32 void f (int); void h (void) { __PTRDIFF_TYPE__ i = -__PTRDIFF_MAX__ - 1; f (L"123456789"[i]); } ;; Function h (h, funcdef_no=0, decl_uid=1841, cgraph_uid=1, symbol_order=0) h () { int i; long int _1; <bb 2> : i_2 = -2147483648; _1 = "1"[i_2]; f (_1); return; } ;; Function h (h, funcdef_no=0, decl_uid=1841, cgraph_uid=1, symbol_order=0) h () { int i; long int _1; <bb 2> : _1 = "1"[-2147483648]; f (_1); return; } ;; Function h (h, funcdef_no=0, decl_uid=1841, cgraph_uid=1, symbol_order=0) h () { <bb 2> [local count: 1073741825]: f (49); return; }