Skip to content

Commit 417b55b

Browse files
committed
JumpThreading: Add test for incorrect Not behaviour
1 parent f7c8928 commit 417b55b

3 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- // MIR for `not_int` before JumpThreading
2+
+ // MIR for `not_int` after JumpThreading
3+
4+
fn not_int() -> i32 {
5+
let mut _0: i32;
6+
let _1: i32;
7+
let mut _2: bool;
8+
let mut _3: i32;
9+
let mut _4: i32;
10+
scope 1 {
11+
debug a => _1;
12+
}
13+
14+
bb0: {
15+
StorageLive(_1);
16+
_1 = const 1_i32;
17+
StorageLive(_2);
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_4 = copy _1;
21+
_3 = Not(move _4);
22+
StorageDead(_4);
23+
_2 = Eq(move _3, const 0_i32);
24+
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
25+
+ goto -> bb1;
26+
}
27+
28+
bb1: {
29+
StorageDead(_3);
30+
_0 = const 1_i32;
31+
goto -> bb3;
32+
}
33+
34+
bb2: {
35+
StorageDead(_3);
36+
_0 = const 0_i32;
37+
goto -> bb3;
38+
}
39+
40+
bb3: {
41+
StorageDead(_2);
42+
StorageDead(_1);
43+
return;
44+
}
45+
}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
- // MIR for `not_int` before JumpThreading
2+
+ // MIR for `not_int` after JumpThreading
3+
4+
fn not_int() -> i32 {
5+
let mut _0: i32;
6+
let _1: i32;
7+
let mut _2: bool;
8+
let mut _3: i32;
9+
let mut _4: i32;
10+
scope 1 {
11+
debug a => _1;
12+
}
13+
14+
bb0: {
15+
StorageLive(_1);
16+
_1 = const 1_i32;
17+
StorageLive(_2);
18+
StorageLive(_3);
19+
StorageLive(_4);
20+
_4 = copy _1;
21+
_3 = Not(move _4);
22+
StorageDead(_4);
23+
_2 = Eq(move _3, const 0_i32);
24+
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
25+
+ goto -> bb1;
26+
}
27+
28+
bb1: {
29+
StorageDead(_3);
30+
_0 = const 1_i32;
31+
goto -> bb3;
32+
}
33+
34+
bb2: {
35+
StorageDead(_3);
36+
_0 = const 0_i32;
37+
goto -> bb3;
38+
}
39+
40+
bb3: {
41+
StorageDead(_2);
42+
StorageDead(_1);
43+
return;
44+
}
45+
}
46+

Diff for: tests/mir-opt/jump_threading.rs

+11
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,15 @@ fn floats() -> u32 {
531531
if x == 0.0 { 0 } else { 1 }
532532
}
533533

534+
fn not_int() -> i32 {
535+
// CHECK-LABEL: fn not_int(
536+
537+
// Test for issue #131195, where !a == b is assumed to be equivalent to a != b
538+
// This is only the case for bools
539+
let a = 1;
540+
if !a == 0 { 1 } else { 0 }
541+
}
542+
534543
fn main() {
535544
// CHECK-LABEL: fn main(
536545
too_complex(Ok(0));
@@ -546,6 +555,7 @@ fn main() {
546555
aggregate(7);
547556
assume(7, false);
548557
floats();
558+
not_int();
549559
}
550560

551561
// EMIT_MIR jump_threading.too_complex.JumpThreading.diff
@@ -562,3 +572,4 @@ fn main() {
562572
// EMIT_MIR jump_threading.assume.JumpThreading.diff
563573
// EMIT_MIR jump_threading.aggregate_copy.JumpThreading.diff
564574
// EMIT_MIR jump_threading.floats.JumpThreading.diff
575+
// EMIT_MIR jump_threading.not_int.JumpThreading.diff

0 commit comments

Comments
 (0)