https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108737
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
CC| |jakub at gcc dot gnu.org
Summary|[13 Regression] Apparent |[13 Regression] Apparent
|miscompile of infinite loop |miscompile of infinite loop
|on gcc trunk in cddce2 pass |on gcc trunk in cddce2 pass
| |since r13-3875
Keywords|needs-bisection |
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The foo definition could be e.g.
extern "C" void exit (int);
int foo() {
static int cnt;
if (cnt++ == 0)
return 1;
if (cnt > 42)
exit (0);
return 0;
}
Yes, if first invocation of foo returns 0, then it would invoke UB in C++, but
if it returns non-zero and isn't const or pure, it can't be optimized this way.
Started with r13-3875-g9e11ceef165bc074c2fc85b8ddece606b24e710b