Skip to content

Commit

Permalink
Add regression test showcasing miscompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvandel committed Sep 19, 2020
1 parent fd702d2 commit cad050b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- // MIR for `encode` before SimplifyBranchSame
+ // MIR for `encode` after SimplifyBranchSame

fn encode(_1: Type) -> Type {
debug v => _1; // in scope 0 at $DIR/76803_regression.rs:10:15: 10:16
let mut _0: Type; // return place in scope 0 at $DIR/76803_regression.rs:10:27: 10:31
let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16

bb0: {
_2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
+ goto -> bb1; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16
}

bb1: {
_0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15
- goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
+ goto -> bb2; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
}

bb2: {
- discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27
- goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6
- }
-
- bb3: {
return; // scope 0 at $DIR/76803_regression.rs:15:2: 15:2
}
}

19 changes: 19 additions & 0 deletions src/test/mir-opt/76803_regression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// compile-flags: -Z mir-opt-level=1
// EMIT_MIR 76803_regression.encode.SimplifyBranchSame.diff

#[derive(Debug, Eq, PartialEq)]
pub enum Type {
A,
B,
}

pub fn encode(v: Type) -> Type {
match v {
Type::A => Type::B,
_ => v,
}
}

fn main() {
assert_eq!(Type::B, encode(Type::A));
}

0 comments on commit cad050b

Please sign in to comment.