[Bug other/98663] gcc generates endless loop at -O2 or greater depending on order of testExpression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98663 --- Comment #5 from charliepdts at gmx dot at --- Hi Jakub, thanks for the detailed description and the insights as to the assumptions that the compiler uses when optimizing code like this.
[Bug other/98663] gcc generates endless loop at -O2 or greater depending on order of testExpression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98663 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- We have a warning but only if the loop doesn't have multiple exits. In your case it has multiple exits and warning on it would be only a false positive for perfectly valid code that would just assume that read[x] would be 0x for at least one i in between 0 and 449 inclusive. Compiler really doesn't have an intention to punish users and break their code, but just assumes the code doesn't trigger undefined behavior. In particular in this case, in some places it computes that the maximum number of iterations of the loop is bounded by not invoking UB with read[450], some other pass will compute value ranges of the iteration and yet another piece of code will determine that the i < 450 condition is always true due to the limited range and thus can be optimized away.
[Bug other/98663] gcc generates endless loop at -O2 or greater depending on order of testExpression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98663 --- Comment #3 from charliepdts at gmx dot at --- While I appreciate the anything can happen, what surprised us was the lack of any kind of warning. Does the compiler not notice the access outside the array in this case? background: we are working with a rather large codebase here for an embedded target which unfortunately does not play nice with gdb. The tracking down of this behaviour took rather long. A warning could have helped us find and eliminate this problem in our code much sooner.
[Bug other/98663] gcc generates endless loop at -O2 or greater depending on order of testExpression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98663 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #2 from Andrew Pinski --- Accessing outside the bounds of an array is undefined behavior so anything can happen.
[Bug other/98663] gcc generates endless loop at -O2 or greater depending on order of testExpression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98663 Dávid Bolvanský changed: What|Removed |Added CC||david.bolvansky at gmail dot com --- Comment #1 from Dávid Bolvanský --- Compiler can do anything if there is UB in the code.