-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
-Zmir-opt-level
miscompiles code with panic
#131195
Comments
|
Yeah, I think so. |
@@ -1,4 +1,4 @@
-// MIR for `myfunc` before JumpThreading
+// MIR for `myfunc` after JumpThreading
fn myfunc() -> i32 {
let mut _0: i32;
@@ -17,7 +17,7 @@ fn myfunc() -> i32 {
_4 = copy _1;
_3 = Not(move _4);
_2 = Ne(move _3, const 0_i32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ goto -> bb2;
}
bb1: { Looks like it's JumpThreading that incorrectly removes the condition |
I managed to create an example without panic, just wrong value pub fn myfunc() -> i32 {
let mut a: i32 = 0;
a = 1;
if !a != 0 {
return 1
}
return 0;
}
pub fn main() {
let mut e = myfunc();
println!("e={}", e);
} % rustc -Awarnings test.rs -Zmir-opt-level=0 && ./test
e=1
% rustc -Awarnings test.rs -Zmir-opt-level=2 && ./test
e=0 |
Most likely #117206 |
ha, I found the bug. We're optimizing @rustbot claim |
…piler-errors JumpThreading: fix bitwise not on non-booleans Fixes rust-lang#131195 Alternative to rust-lang#131201
I tried this code:
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
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: