The C11 standard appears to imply that iteration statements with constant controlling expressions should not be optimized out. I\'m taking my advice from this answer, which
Other answers already covered ways to make Clang emit the infinite loop, with inline assembly language or other side effects. I just want to confirm that this is indeed a compiler bug. Specifically, it's a long-standing LLVM bug - it applies the C++ concept of "all loops without side-effects must terminate" to languages where it shouldn't, such as C.
For example, the Rust programming language also allows infinite loops and uses LLVM as a backend, and it has this same issue.
In the short term, it appears that LLVM will continue to assume that "all loops without side-effects must terminate". For any language that allows infinite loops, LLVM expects the front-end to insert llvm.sideeffect
opcodes into such loops. This is what Rust is planning to do, so Clang (when compiling C code) will probably have to do that too.