[Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jan 22 09:36:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to janus from comment #0)
> with -O2 and -O3, while 4.8 did not do that. Probably the warning is ok,
> since the test case is supposed to trigger a runtime error ("Index '5' of
> dimension 2 of array 'a' outside of expected range (4:1)").
Of course the warning is correct.
>
> However, I see three possible problems:
> 1) The question is why it only happens with SAVE.
I get the warning also without SAVE. Furthermore, the warning is not
guaranteed for all undefined behaviors in the loop of course, only if the loop
has known constant number of iterations, no early exits and is known to trigger
selected kinds of undefined behavior in some of the iterations.
> 2) I don't understand why the warning has 'iteration 4'. Shouldn't iteration
> 5 be the problem?
This is a middle-end warning, I don't see how the middle-end could find out
that the frontend wants to count the iterations differently.
> 3) The warning appears twice.
For that I have an untested fix:
2014-01-22 Jakub Jelinek <jakub@redhat.com>
PR middle-end/59561
* cfgloopmanip.c (copy_loop_info): If
loop->warned_aggressive_loop_optimizations, make sure
the flag is set in target loop too.
--- gcc/cfgloopmanip.c.jj 2014-01-03 11:40:33.000000000 +0100
+++ gcc/cfgloopmanip.c 2014-01-22 10:21:54.057871045 +0100
@@ -1022,6 +1022,8 @@ copy_loop_info (struct loop *loop, struc
target->any_estimate = loop->any_estimate;
target->nb_iterations_estimate = loop->nb_iterations_estimate;
target->estimate_state = loop->estimate_state;
+ target->warned_aggressive_loop_optimizations
+ |= loop->warned_aggressive_loop_optimizations;
}
/* Copies copy of LOOP as subloop of TARGET loop, placing newly
More information about the Gcc-bugs
mailing list