https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99101
--- Comment #17 from Michael Matz <matz at gcc dot gnu.org> --- (In reply to Richard Biener from comment #16) > Of course since -ffinite-loops and the C++ standard require forward progress > here and all testcases expect the loop to not terminate we're in the realm > of undefined behavior. But I'm not yet convinced the control-dependence / > CD-DCE issue only shows up in such cases. That said, it's fully expected > that > > int xx; > int main() > { > int jobs_ = 1; > int at_eof_ = 0; > while (1) > { > for (int i = 0; i < jobs_; i++) > { > if (at_eof_) > continue; > at_eof_ = 1; > if (xx) > return 1; > } > jobs_ = 0; > } > return 0; > } > > is eventually optimized to just return 1 with -ffinite-loops and we should > try to preserve that behavior. Just commenting on this last statement: I think that's wrong. It's provable that 'xx' doesn't change in the loop, and that it starts out as 0 (this is main here). So in fact we have produced an endless loop without a return, and hence can do anything (when endless loops are undefined).