2 ms·
Ah, nomenclature fail on my part. You're right, it's LLVM. This is an LLVM bug - it affects C code too (when it should only apply to C++). If you compile this
by nneonneo 7y ago
Ah, nomenclature fail on my part. You're right, it's LLVM.
This is an LLVM bug - it affects C code too (when it should only apply to C++). If you compile this code:
static void die() { while(1) ; }
int main() { die(); }
as a C program with optimizations, it will die with an illegal instruction too.
- zzo38computer 7y agoPerhaps it should be allow to optimize it to: int main() { while(1) pause(); } But only if system call optimizations are enabled (otherwise it can't add the call to pause()), and only if you did not specifically disable the optimization for infinite loops, and only if you do not use the -Os option.
- saagarjha 7y agoCorrect, the bug is that LLVM (being mostly built around C++?) did not have a concept of infinite loops that could not be removed for quite a while. Here's the Rust bug about this, which also contains links to relevant discussion on the LLVM side, including some forward progress: https://github.com/rust-lang/rust/issues/28728 https://github.com/rust-lang/rust/issues/28728. I believe the current status is that machinery has been added that language frontends can use to mark loops as having side effects, which will indicate to LLVM that they should not be optimized out.
- jfkebwjsbx 7y agoIt is not a bug in the broken sense since it was intended. There is simply no way to create an infinite loop in LLVM IR. You could argue it is Clang generating bad LLVM IR for C mode, same as Rust. They could add something to the generated IR to make it formally finite.