My "favourite" recent compiler bug comes from Rust. Compile the following code in Release mode:
fn main() { (|| loop {})() }
This defines an anonymous function containing an infinite loop, and calls it. Any sane compiler would make this just loop forever, right?
$ cargo run --release test
Illegal instruction (core dumped)
Yeah, that's right. In
Rust
, an ostensibly safe language, Clang's overeager optimizer chooses to emit an
illegal instruction in lieu of an infinite loop. (Try it here:
https://play.rust-lang.org/?version=stable&mode=release&edit...)
This particular bug actually comes from C++. In C++, threads may be assumed to always make forward progress, i.e. side-effect-free infinite loops are UB. However, this is not true in C, and it's definitely not true in Rust, yet Clang makes this assumption anyway.
It gets a lot worse; once Clang sees an infinite loop and decides it's UB, it gets to make all sorts of thoroughly invalid and silly "optimizations"; see this SO question for some examples: https://stackoverflow.com/questions/59925618/how-do-i-make-a...
This particular bug actually comes from C++. In C++, threads may be assumed to always make forward progress, i.e. side-effect-free infinite loops are UB. However, this is not true in C, and it's definitely not true in Rust, yet Clang makes this assumption anyway.
It gets a lot worse; once Clang sees an infinite loop and decides it's UB, it gets to make all sorts of thoroughly invalid and silly "optimizations"; see this SO question for some examples: https://stackoverflow.com/questions/59925618/how-do-i-make-a...