-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite recursion optimized away with opt-level=z
#97428
Comments
opt-level=z
According to #28728 (comment) and https://www.llvm.org/docs/LangRef.html#llvm-loop-mustprogress-metadata, rustc doesn't emit |
This was apparently working in 1.58 and regressed in 1.59. @rustbot label regression-from-stable-to-stable |
Small reproducer: https://github.com/ldm0/rust_test1 $ cargo run --release
Finished release [optimized] target(s) in 0.04s
Running `target/release/rust_test1`
start
done: Run { a: false, b: false, c: None } |
From a cursory look, probably due to: https://github.com/llvm/llvm-project/blob/cc871cf6b50f6a76f2083d192e2254a16832224b/llvm/lib/Transforms/Utils/Local.cpp#L2369 |
From cargo bisect:
Probably related to #88243 |
I'm tagging this as The following reproduction is concerning: #[derive(Default)]
pub struct Run {
pub a: Option<String>,
}
impl Run {
#[inline(never)]
pub fn run(&mut self) -> ! {
self.run()
}
}
pub fn foo() -> Run {
let mut run = Run::default();
run.run();
run
}
fn main() {
foo();
} This exits with an |
Upstream fix: llvm/llvm-project@2e101cc Upstream backport issue: llvm/llvm-project#55777 |
Reopening to beta-nominate. This regression is a nasty miscompilation that can silently induce unsoundness in valid code, given a certain opt-level setting, and is not platform-specific. The patch to LLVM to fix this is quite small: llvm/llvm-project@ |
As per T-compiler meeting (Zulip notes), lowering priority of this issue since has been there for a long time and the "illegal hardware instruction" mentioned is the @rustbot label +P-high -P-critical |
Update LLVM submodule Merge upstream release/14.x branch. Fixes rust-lang#97428.
Closing this as the beta backport has happened. |
I tried this code:
I expected to see this happen:
foo
runs infinitelyInstead, this happened:
foo
return directlyThe
opt-level
is set toz
: https://rust.godbolt.org/z/n1v471j6EThe text was updated successfully, but these errors were encountered: