[Bug c/59933] for loop goes wild with assert() enabled

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 19 15:49:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59933

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The code is not invalid C, just triggers undefined behavior, so it is not
invalid at compile time, just at runtime if you ever hit this.
GCC optimizes based on the assumption that undefined behavior doesn't happen in
a correct program.
While we have -Waggressive-loop-optimizations warning, it (intentionally) warns
solely about the case where the loop has single exit and constant loop
iteration count, which is not the case here, the number of iterations is
i >= 292 ? 0 : 292 - i.
The loop will trigger undefined behavior whenever i is < 292, if it is bigger,
then there is no bug.



More information about the Gcc-bugs mailing list