[Bug c++/91475] Optimization causes infinite loop

2019-08-16 Thread eric_musser at yahoo dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91475

--- Comment #2 from Eric Musser  ---
But in this case the undefineness is not directly related to the for loop.
Further the optimizer that changes the loop to maintain and compare j *
0x2001 as opposed to just j could detect certain overflow as the upperbound
for the loop is a constant (j < 9) -- since 9 * 0x2001 > (1<<31). In this
case the optimization could either be disabled or produce a warning. The fact
the end-condition of the for loop is optimized away completely suggests this is
not a runtime issue (the infinite loop is hardcoded into resulting assembly).

In the case the upperbound of the for loop is variable I agree it is not
possible to detect nor may it be worth disabling the optimization if there is
only a chance of overflow.

[Bug c++/91475] Optimization causes infinite loop

2019-08-16 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91475

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  ---
Signed integer overflow is undefined at runtime; this means we cannot error out
when it happens at compile time.  The warning is not done for loops on purpose
since those are normally places where the user wants to take advantage of the
undefineness.

Use -fsanitize=undefined to find it at runtime.
It is hard sometimes to find that the code will run into this code.