-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Jump on unitialized memory when returning from closure with --opt-level=2 #15932
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
Comments
In the past I've seen false positives (#11710) produced by valgrind, but I'm not sure if this falls in that category. |
The corresponding LLVM bug is http://llvm.org/bugs/show_bug.cgi?id=12319 |
This isn't a bug but rather a known a consequence of enabling optimizations. If LLVM does provide a way to deal with this, it will be in the form of a lower optimization level compatible with Valgrind. It's always going to happen at the normal optimization level unless they cripple the instruction scheduling to avoid Valgrind false positives. There's nothing Rust can do about it at a compiler / library level, although it could be mentioned in documentation. |
FWIW, this still occurs on rust 1.6. Note that a closure isn't necessary: use self::Instruction::*;
#[derive(PartialEq, Eq, Debug)]
enum Instruction {
Increment {
amount: i8,
},
Loop {
body: Vec<Instruction>,
},
}
fn is_zero_inc(instr: &Instruction) -> bool {
if let Increment { amount: 0 } = *instr {
return false;
}
true
}
fn combine_increments(instrs: Vec<Instruction>) -> Vec<Instruction> {
instrs.into_iter()
.filter(is_zero_inc)
.collect()
}
fn main() {
let instrs = vec![Increment { amount: 1 },
Loop { body: vec![Increment { amount: -1 }] },
Increment { amount: 1 },
Increment { amount: 1 }];
println!("{:?}", combine_increments(instrs));
} Compiling with optimisations, then running with valgrind gives:
It would be nice to document this, but I'm not sure where in the docs would be the natural place to put it. |
@thestinger Is there an rustc optimization level that should work with Valgrind? |
Just turn off that Valgrind feature, it doesn't work with modern optimizing compilers. Rust could support sanitizers instead. |
The following code has a valgrind error when compiled with --opt-level=2 or greater. I have a mystery crash in a program of mine whenever optimizations are enabled, and hitting this is the first sign of anything amiss.
The offending line is the
box 0u
. The weirdmatch &match var { ... } { ... }
expression comes from inside aformat!
Edit: My crash had nothing to do with this. I don't think this is a serious bug.
The text was updated successfully, but these errors were encountered: