Test: int x[10]; void fn () { int i; for (i = 0; i < 100; ++i) x[i] = 1; } Using trunk at r198689: gcc -O2 -c t.c t.c: In function ‘fn’: t.c:8:10: warning: iteration 10u invokes undefined behavior [-Waggressive-loop-optimizations] x[i] = 1; ^ t.c:7:3: note: containing loop for (i = 0; i < 100; ++i) ^ Looks good. But this doesn't: gcc -O2 -c t.c -w t.c: In function ‘fn’: t.c:7:3: note: containing loop for (i = 0; i < 100; ++i) ^ A note suddenly appears from "nowhere" :-(
This issue is easy, isn't it? Something like: Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 198676) +++ tree-ssa-loop-niter.c (working copy) @@ -2553,10 +2553,11 @@ do_warn_aggressive_loop_optimizations (struct loop return; gimple estmt = last_stmt (e->src); - warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations, - "iteration %E invokes undefined behavior", - double_int_to_tree (TREE_TYPE (loop->nb_iterations), i_bound)); - inform (gimple_location (estmt), "containing loop"); + if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations, + "iteration %E invokes undefined behavior", + double_int_to_tree (TREE_TYPE (loop->nb_iterations), + i_bound))) + inform (gimple_location (estmt), "containing loop"); loop->warned_aggressive_loop_optimizations = true; }
(In reply to comment #1) > This issue is easy, isn't it? Something like: > > Index: tree-ssa-loop-niter.c > =================================================================== > --- tree-ssa-loop-niter.c (revision 198676) > +++ tree-ssa-loop-niter.c (working copy) > @@ -2553,10 +2553,11 @@ do_warn_aggressive_loop_optimizations (struct loop > return; > > gimple estmt = last_stmt (e->src); > - warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations, > - "iteration %E invokes undefined behavior", > - double_int_to_tree (TREE_TYPE (loop->nb_iterations), i_bound)); > - inform (gimple_location (estmt), "containing loop"); > + if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations, > + "iteration %E invokes undefined behavior", > + double_int_to_tree (TREE_TYPE (loop->nb_iterations), > + i_bound))) > + inform (gimple_location (estmt), "containing loop"); > loop->warned_aggressive_loop_optimizations = true; > } Yes, approved.
Done, mainline and 4.8.1.