On Wed, Nov 5, 2014 at 10:45 PM, Andrew Stubbs <a...@codesourcery.com> 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?

Please find a better way to communicate possibly_undefined_stmt than
enlarging struct loop.  Like associating it with the niter bound
we record (so you can also have more than one).

Thanks,
Richard.

> Andrew

Reply via email to