3 ms·
The purpose of the construction could be to inform the compiler of the fact that the condition is always false, so as to enable the compiler optimizer more. Ta
by nsajko 2y ago
The purpose of the construction could be to inform the compiler of the fact that the condition is always false, so as to enable the compiler optimizer more.
Take a look at these features in C++, LLVM or Rust if you're not familiar with the concept:
* https://en.cppreference.com/w/cpp/utility/unreachable https://en.cppreference.com/w/cpp/utility/unreachable
* https://en.cppreference.com/w/cpp/language/attributes/assume https://en.cppreference.com/w/cpp/language/attributes/assume
* https://en.cppreference.com/w/cpp/memory/assume_aligned https://en.cppreference.com/w/cpp/memory/assume_aligned
* https://llvm.org/docs/LangRef.html#unreachable-instruction https://llvm.org/docs/LangRef.html#unreachable-instruction
* https://llvm.org/docs/LangRef.html#llvm-assume-intrinsic https://llvm.org/docs/LangRef.html#llvm-assume-intrinsic
* https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked....
* https://doc.rust-lang.org/std/hint/fn.assert_unchecked.html https://doc.rust-lang.org/std/hint/fn.assert_unchecked.html
The infinite loop is effectively an unreachable instruction (reaching it is not allowed), and an unreachable instruction behind a branch effectively becomes an assume instruction.
- SomeoneFromCA 2y agoNo, it cannot, as while (true) {} is not UB and should not be optimized out. EDIT: oops, yes you are right, it is not c++ after all.