3 ms·
I don't know the root cause of the noalias miscompilation, the thing I was referring to is https://github.com/rust-lang/rust/issues/28728 https://github.com/rus
by steveklabnik 6y ago
I don't know the root cause of the noalias miscompilation, the thing I was referring to is https://github.com/rust-lang/rust/issues/28728 https://github.com/rust-lang/rust/issues/28728
TL;DR: C++ says that an infinite loop with no side effects is UB, Rust does not. Empty loops in Rust will disappear entirely when they should really loop forever.
(I edited my comment slightly because, re-reading, "blindly" sounds too negative.)
- davidhyde 6y agoGreat point! If anyone is curious about how to write an “empty” loop that is not compiled away, I've seen this common implementation that doesn’t even need the standard library: loop { core::sync::atomic::compiler_fence( core::sync::atomic::Ordering::SeqCst); }
- jdoerfert 6y agoSince https://reviews.llvm.org/D86841 https://reviews.llvm.org/D86841, ~ Aug 2020, Clang is able to reason about the forward progress guarantees of the input. For the LLVM-IR handling see https://reviews.llvm.org/D86233 https://reviews.llvm.org/D86233. While we are still adding more fine-grained support of different language standards and corner cases, e.g., constant loop condition in C vs. C++, you should be able to tell LLVM a loop is allowed to loop forever w/o side-effect. In fact, that is the new default. That said, LLVM still removes calls to functions without side effect unconditionally. We are working on that, i.a., https://reviews.llvm.org/D94106 https://reviews.llvm.org/D94106.