https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86691
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=86613, | |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=86611 Blocks| |56456 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- See also pr86613 and pr86611 for other examples of missing -Warray-bounds due to early folding of out-of-bounds accesses by different passes. It's possible that they all could be due to the same underlying bug. The one here is the result of the folding in fold_array_ctor_reference() in gimple-fold.c. The function ends with the following: /* Memory not explicitly mentioned in constructor is 0 (or the reference is out of range). */ return type ? build_zero_cst (type) : NULL_TREE; } However, negative indices are not folded as a result of the following code in fold_const_aggregate_ref_1(), also in gimple-fold.c: /* Out of bound array access. Value is undefined, but don't fold. */ if (maybe_lt (offset, 0)) return NULL_TREE; So it seems that fold_array_ctor_reference() needs to also avoid folding out-of-bounds array references. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds