-
Notifications
You must be signed in to change notification settings - Fork 75
Some mirunsafeck and thirunsafeck tests failing with weird assert failure #96
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
I ran this with before (full file with more debug info here: fake.c.036t.ealias.txt)
and after: (full file here: fake.c.037t.fre1.txt)
|
I can't remember all the details of my tests, but it seems something was needed in order to reproduce the issue outside the UI tests (maybe it was to compile with(out?) optimizations?). |
The issue did happen for me, the assert condition gets deleted and then the assert panic gets called even though the two values are equal. |
The issue happens even without the fn main() {
unsafe {
let mut u = 0xDE_DE_u16;
*(&mut u as *mut _ as *mut u8) = 0xBE;
match (&u, 0xDE_BE_u16) {
(a, b) => {
if !(*a == b) {
println!("how did this happen, a={}, b={}", *a, b);
}
}
}
}
} (edit: removed the reference from the right-hand side of the match) |
Maybe minimized it a bit more: fn main() {
unsafe {
let mut u = 0xDE_DE_u16;
*(&mut u as *mut _ as *mut u8) = 0xBE;
let a = &u;
let b = *a;
println!("a={:?}, *a={:?}, b={:?}", a, *a, b);
}
} prints:
|
I'd be curious to see the MIR and the GIMPLE for that. |
I'm actually not so sure the last example is as useful for minimization because How do I get the MIR?
Last I checked, yes. |
Does |
@sapir Could you try compiling with |
mytest.main.005-024.PreCodegen.after.mir.txt
yes it works! |
Wouldn't that have the same effect as |
No, that flag disable the optimization, while using a union would make it understand that those pointer aliases (at least, that's my understanding; I haven't had the time to read that article). |
As far as I understand casting through unions is not enough. If a function takes two pointers of different types, strict aliasing will assume that they don't alias AFAIK, but rust allows this just fine. |
You're right. Rust relies on LLVM not doing TBAA. |
That happens only when compiled in release mode, not in debug mode.
Example:
gives:
The text was updated successfully, but these errors were encountered: