-
Notifications
You must be signed in to change notification settings - Fork 13k
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
LLVM miscompiles large stack allocations #100914
Comments
Can reproduce that it emits So this does indeed seem to be either a false positive on that side, or unsoundness. I have no idea why it only appears if you have a 4GB long stack buffer.... (Maybe using an Interesting data point: it does not warn if you use address sanitizer. |
On |
Also, valgrind does complain
what this means, I have no clue. |
Here's a slightly minimized reproducer: use std::thread;
const KILO: usize = 1024;
const MEGA: usize = 1024 * KILO;
const GIGA: usize = 1024 * MEGA;
// max failing
//const BUFFER_SIZE: usize = 4 * GIGA + 16;
const BUFFER_SIZE: usize = 4 * GIGA;
const REQUIRED_STACK_SIZE: usize = 512 * MEGA + BUFFER_SIZE;
fn main() {
thread::Builder::new()
.stack_size(REQUIRED_STACK_SIZE)
.spawn(perform_double_free)
.unwrap()
.join()
.unwrap();
}
fn perform_double_free() {
let v1 = vec![0];
let v2 = vec![0];
verbose_drop(v2);
verbose_drop(v1);
println!("never reached");
let buffer = [0u8; BUFFER_SIZE];
mark_buffer_used(&buffer);
}
#[inline(never)]
fn verbose_drop(x: Vec<i32>) {
println!("dropping vec at {:?}", x.as_ptr());
}
fn mark_buffer_used(buffer: &[u8]) {
println!("{}", buffer[0]);
} Prints:
If
Relevant section from the assembly (with
The first vector is stored at |
This issue seems related to this one. |
I've been able to bisect this back to 2018-05-03 as the earliest failing nightly (2018-04-30 does not reproduce it). |
@Cl00e9ment, could you post the following? @rustbot label +T-compiler +I-unsound I think those labels should be right, there is definitely a miscompilation happening somewhere. Hopefully that'll draw some attention here. Edit: nevermind, worked when I did it! Apparently the author-only restriction is only on pull requests. |
Possibly the same issue as #83060 |
@wesleywiser points out that this might be related to LLVM issue llvm/llvm-project#48911 |
Discussed during T-compiler 2023 Q1 P-high review See commented added to end of #83060, starting with #83060 (comment) |
Program output seems to have changed since
|
This should be fixed by llvm/llvm-project#101840 |
P-high triage: upstream PR was reverted due to hitting an assertion, cause/solution unclear, reverted in llvm/llvm-project@768598b. |
I tried this code:
I expected the program to exit normally.
Instead, this happened:
Meta
Tested on Linux with the following Rust versions :
rustc 1.63.0 (4b91a6ea7 2022-08-08)
rustc 1.64.0-beta.3 (82bf34178 2022-08-18)
rustc 1.65.0-nightly (015a824f2 2022-08-22)
Only reproducible with
--release
.Can be reproduced on Windows inside a Rust Docker container.
The program may use about 5 GiB of memory and may hang the system. So be sure to have enough space and be ready to kill the process.
Backtrace
No backtrace is printed with
RUST_BACKTRACE=1
.The text was updated successfully, but these errors were encountered: