Skip to content

Commit b658050

Browse files
committed
Demonstrate the bug
1 parent 39c6804 commit b658050

2 files changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -Zmir-opt-level=2 -Zinline-mir
2+
// ignore-debug: standard library debug assertions add a panic that breaks this optimization
3+
#![crate_type = "lib"]
4+
5+
pub enum Thing {
6+
A,
7+
B,
8+
}
9+
10+
// EMIT_MIR instcombine_duplicate_switch_targets_e2e.ub_if_b.PreCodegen.after.mir
11+
pub unsafe fn ub_if_b(t: Thing) -> Thing {
12+
match t {
13+
Thing::A => t,
14+
Thing::B => std::hint::unreachable_unchecked(),
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// MIR for `ub_if_b` after PreCodegen
2+
3+
fn ub_if_b(_1: Thing) -> Thing {
4+
debug t => _1; // in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+0:23: +0:24
5+
let mut _0: Thing; // return place in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+0:36: +0:41
6+
let mut _2: isize; // in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+2:9: +2:17
7+
scope 1 (inlined unreachable_unchecked) { // at $DIR/instcombine_duplicate_switch_targets_e2e.rs:14:21: 14:55
8+
scope 2 {
9+
scope 3 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
10+
}
11+
}
12+
}
13+
14+
bb0: {
15+
_2 = discriminant(_1); // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+1:11: +1:12
16+
switchInt(move _2) -> [0: bb2, 1: bb1, otherwise: bb1]; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+1:5: +1:12
17+
}
18+
19+
bb1: {
20+
unreachable; // scope 2 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
21+
}
22+
23+
bb2: {
24+
_0 = move _1; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+2:21: +2:22
25+
return; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+5:2: +5:2
26+
}
27+
}

0 commit comments

Comments
 (0)