Ping.

On 05/11/14 21:45, Andrew Stubbs wrote:
This patch adds the following warning message:

undefined.c:9:20: warning: statement may be undefined in the final loop
iteration. [-Waggressive-loop-optimizations]
    for (i = 0; array[i] && i < 5; i++)
                     ^

(Where the code ought to read "i < 5 && array[i]".)

The tree-ssa loop optimizations already eliminate useless loop-exit
conditions (i.e. conditions that will never be true). Unfortunately,
they also eliminate exit conditions that can be true, but only after
undefined behaviour has occurred. Typically, that means that the
undefined behaviour becomes an infinite loop (if it doesn't happen to
crash, of course), and that's surprising. It also looks more like a
compiler bug than a crash does.

The new warning should highlight these cases but does not actually
change anything. I've included a comment where the compiler could be
adjusted to avoid the surprising optimization. Would it be appropriate
to do so?

OK to commit?

Andrew

Reply via email to