Closed
Description
The following snippet crashes when compiled in release mode on current stable, beta and nightly:
enum Null {}
fn foo() -> Null { loop { } }
fn create_null() -> Null {
let n = foo();
let mut i = 0;
while i < 100 { i += 1; }
return n;
}
fn use_null(n: Null) -> ! {
match n { }
}
fn main() {
use_null(create_null());
}
https://play.rust-lang.org/?gist=1f99432e4f2dccdf7d7e&version=stable
This is based on the following example of LLVM removing a loop that I was made aware of: https://github.com/simnalamburt/snippets/blob/12e73f45f3/rust/infinite.rs.
What seems to happen is that since C allows LLVM to remove endless loops that have no side-effect, we end up executing a match
that has no arms.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Issue: In need of a decision.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessMedium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Working group: Embedded systems