https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94392
--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> --- On Mon, 30 Mar 2020, joseph at codesourcery dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94392 > > --- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery > dot com> --- > I'm not sure the existing infinite loop removal is valid for any C > standard version. The C (C11 and later) rule against infinite loops only > applies when the loop is written as an iteration statement whose > controlling expression is not constant (not if it's written with goto, or > has a constant controlling expression); it's not the more general rule > about forward progress that C++ has. For the middle-end feature we need to define what loops we consider finite in middle-end terms which currently is that the loop has at least one "normal" (non-EH, non-abnormal) exit. In that case the middle-end assumes the loop will eventually terminate. That in particular means if the middle-end removes all exits as unreachable then the loop will no longer appear finite. I think the middle-end never introduces additional normal exits so any loop that did not contain an exit at the source AST level should never appear finite. So iff the C rule forbids while (a) {} to be infinite but does _not_ forbid while (1) {} to be infinite this is in-line with the middle-end implementation. I _think_ the C++ standard disallows while (1) {}, too.