Description
I tried this code:
pub fn myfunc() -> i32 {
let mut c :i32 = 1;
c = 1 ;
if !c != 0 {
return 1;
}
panic!("Reached end of non-void function");
}
pub fn main() {
let e = myfunc();
println!("e={}", e);
}
I expected to see this happen: always panic
Instead, this happened: only -Zmir-opt-level=2 panic
For mir-opt-level 0, 1 and 3, they all normally return
% rustc -Awarnings -Zmir-opt-level=2 test.rs && ./test
thread 'main' panicked at test.rs:7:5:
Reached end of non-void function
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
%
% rustc -Awarnings -Zmir-opt-level=0 test.rs && ./test
e=1
Meta
rustc --version --verbose
:
rustc 1.83.0-nightly (18b1161ec 2024-10-02)
binary: rustc
commit-hash: 18b1161ec9eeab8927f91405bca0ddf59a4a26c9
commit-date: 2024-10-02
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
Metadata
Metadata
Assignees
Labels
Area: MIR optimizationsCategory: This is a bug.Issue: Correct Rust code lowers to incorrect machine codeIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessCritical priorityRelevant to the compiler team, which will review and decide on the PR/issue.