Skip to content

Commit cad050b

Browse files
committed
Add regression test showcasing miscompilation
1 parent fd702d2 commit cad050b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- // MIR for `encode` before SimplifyBranchSame
2+
+ // MIR for `encode` after SimplifyBranchSame
3+
4+
fn encode(_1: Type) -> Type {
5+
debug v => _1; // in scope 0 at $DIR/76803_regression.rs:10:15: 10:16
6+
let mut _0: Type; // return place in scope 0 at $DIR/76803_regression.rs:10:27: 10:31
7+
let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16
8+
9+
bb0: {
10+
_2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
11+
- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
12+
+ goto -> bb1; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
13+
}
14+
15+
bb1: {
16+
_0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15
17+
- goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
18+
+ goto -> bb2; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
19+
}
20+
21+
bb2: {
22+
- discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27
23+
- goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
24+
- }
25+
-
26+
- bb3: {
27+
return; // scope 0 at $DIR/76803_regression.rs:15:2: 15:2
28+
}
29+
}
30+

src/test/mir-opt/76803_regression.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -Z mir-opt-level=1
2+
// EMIT_MIR 76803_regression.encode.SimplifyBranchSame.diff
3+
4+
#[derive(Debug, Eq, PartialEq)]
5+
pub enum Type {
6+
A,
7+
B,
8+
}
9+
10+
pub fn encode(v: Type) -> Type {
11+
match v {
12+
Type::A => Type::B,
13+
_ => v,
14+
}
15+
}
16+
17+
fn main() {
18+
assert_eq!(Type::B, encode(Type::A));
19+
}

0 commit comments

Comments
 (0)