https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64277
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2015-01-26 Ever confirmed|0 |1 --- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- Confirmed btw. I believe we have plenty of dups of this report - it is usually the last peeled iteration we warn for. The interesting thing is that we have # RANGE [1, 11] NONZERO 15 i_385 = i_369 + 1; ... <bb 52>: # RANGE [1, 11] NONZERO 15 i_461 = ASSERT_EXPR <i_385, i_385 < prephitmp_422>; ... <bb 20>: # RANGE [0, 10] NONZERO 15 # i_82 = PHI <i_461(52)> still we compute i_461: [14, 32766] EQUIVALENCES: { i_385 } (1 elements) so sth is bogus here (the above ranges are simply copied in unrolling but that's ok - they are conservatively correct). We should be able to rely on the previous ranges and use them to our advantage, like with Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 220107) +++ gcc/tree-vrp.c (working copy) @@ -847,6 +847,23 @@ update_value_range (const_tree var, valu value_range_t *old_vr; bool is_new; + /* If there is a value-range on the SSA name from earlier analysis + factor that in. */ + if (INTEGRAL_TYPE_P (TREE_TYPE (var))) + { + wide_int min, max; + value_range_type rtype = get_range_info (var, &min, &max); + if (rtype == VR_RANGE || rtype == VR_ANTI_RANGE) + { + value_range_d nr; + nr.type = rtype; + nr.min = wide_int_to_tree (TREE_TYPE (var), min); + nr.max = wide_int_to_tree (TREE_TYPE (var), max); + nr.equiv = NULL; + vrp_intersect_ranges (new_vr, &nr); + } + } + /* Update the value range, if necessary. */ old_vr = get_value_range (var); is_new = old_vr->type != new_vr->type which cuts down the number of warnings to t.c: In function 'foo': t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] a[i] = f1[i]; ^ t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] t.c:12:14: warning: 'f1' may be used uninitialized in this function [-Wmaybe-uninitialized] f1[i] = f1[i] + 1; ^ from t.c: In function 'foo': t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] a[i] = f1[i]; ^ t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] t.c:18:16: warning: array subscript is above array bounds [-Warray-bounds] t.c:12:14: warning: 'f1' may be used uninitialized in this function [-Wmaybe-uninitialized] f1[i] = f1[i] + 1; ^