Skip to content

Commit

Permalink
Rollup merge of rust-lang#75580 - JulianKnodt:or_pattern, r=wesleywiser
Browse files Browse the repository at this point in the history
Add test for checking duplicated branch or-patterns

This adds a regression test for checking `or-patterns` in MIR as shown in rust-lang#75439.
This doesn't introduce a fix as I'm not sure where it would go(I suspect maybe here: src/librustc_mir_build/build/matches/mod.rs), and I'm not particularly able to fix it.

cc: @lzutao
  • Loading branch information
matklad authored Sep 4, 2020
2 parents 4ffb5c5 + c6ab3ff commit 1893161
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/mir-opt/issues/issue-75439.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// EMIT_MIR issue_75439.foo.MatchBranchSimplification.diff

#![feature(const_fn_transmute)]
#![feature(or_patterns)]

use std::mem::transmute;

pub fn foo(bytes: [u8; 16]) -> Option<[u8; 4]> {
// big endian `u32`s
let dwords: [u32; 4] = unsafe { transmute(bytes) };
const FF: u32 = 0x0000_ffff_u32.to_be();
if let [0, 0, 0 | FF, ip] = dwords {
Some(unsafe { transmute(ip) })
} else {
None
}
}

fn main() {
let _ = foo([0; 16]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
- // MIR for `foo` before MatchBranchSimplification
+ // MIR for `foo` after MatchBranchSimplification

fn foo(_1: [u8; 16]) -> std::option::Option<[u8; 4]> {
debug bytes => _1; // in scope 0 at $DIR/issue-75439.rs:8:12: 8:17
let mut _0: std::option::Option<[u8; 4]>; // return place in scope 0 at $DIR/issue-75439.rs:8:32: 8:47
let _2: [u32; 4]; // in scope 0 at $DIR/issue-75439.rs:10:9: 10:15
let mut _3: [u8; 16]; // in scope 0 at $DIR/issue-75439.rs:10:47: 10:52
let mut _5: [u8; 4]; // in scope 0 at $DIR/issue-75439.rs:13:14: 13:38
let mut _6: u32; // in scope 0 at $DIR/issue-75439.rs:13:33: 13:35
scope 1 {
debug dwords => _2; // in scope 1 at $DIR/issue-75439.rs:10:9: 10:15
let _4: u32; // in scope 1 at $DIR/issue-75439.rs:12:27: 12:29
scope 3 {
debug ip => _4; // in scope 3 at $DIR/issue-75439.rs:12:27: 12:29
scope 4 {
}
}
}
scope 2 {
}

bb0: {
StorageLive(_2); // scope 0 at $DIR/issue-75439.rs:10:9: 10:15
StorageLive(_3); // scope 2 at $DIR/issue-75439.rs:10:47: 10:52
_3 = _1; // scope 2 at $DIR/issue-75439.rs:10:47: 10:52
_2 = std::intrinsics::transmute::<[u8; 16], [u32; 4]>(move _3) -> bb1; // scope 2 at $DIR/issue-75439.rs:10:37: 10:53
// mir::Constant
// + span: $DIR/issue-75439.rs:10:37: 10:46
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn([u8; 16]) -> [u32; 4] {std::intrinsics::transmute::<[u8; 16], [u32; 4]>}, val: Value(Scalar(<ZST>)) }
}

bb1: {
StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:10:52: 10:53
switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:12:13: 12:14
}

bb2: {
switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:12:16: 12:17
}

bb3: {
switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:12:19: 12:20
}

bb4: {
discriminant(_0) = 0; // scope 1 at $DIR/issue-75439.rs:15:9: 15:13
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:12:5: 16:6
}

bb5: {
StorageLive(_5); // scope 3 at $DIR/issue-75439.rs:13:14: 13:38
StorageLive(_6); // scope 4 at $DIR/issue-75439.rs:13:33: 13:35
_6 = _4; // scope 4 at $DIR/issue-75439.rs:13:33: 13:35
_5 = std::intrinsics::transmute::<u32, [u8; 4]>(move _6) -> bb8; // scope 4 at $DIR/issue-75439.rs:13:23: 13:36
// mir::Constant
// + span: $DIR/issue-75439.rs:13:23: 13:32
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) -> [u8; 4] {std::intrinsics::transmute::<u32, [u8; 4]>}, val: Value(Scalar(<ZST>)) }
}

bb6: {
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:12:27: 12:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:12:27: 12:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:12:5: 16:6
}

bb7: {
StorageLive(_4); // scope 1 at $DIR/issue-75439.rs:12:27: 12:29
_4 = _2[3 of 4]; // scope 1 at $DIR/issue-75439.rs:12:27: 12:29
goto -> bb5; // scope 1 at $DIR/issue-75439.rs:12:5: 16:6
}

bb8: {
StorageDead(_6); // scope 4 at $DIR/issue-75439.rs:13:35: 13:36
((_0 as Some).0: [u8; 4]) = move _5; // scope 3 at $DIR/issue-75439.rs:13:9: 13:39
discriminant(_0) = 1; // scope 3 at $DIR/issue-75439.rs:13:9: 13:39
StorageDead(_5); // scope 3 at $DIR/issue-75439.rs:13:38: 13:39
StorageDead(_4); // scope 1 at $DIR/issue-75439.rs:14:5: 14:6
goto -> bb9; // scope 1 at $DIR/issue-75439.rs:12:5: 16:6
}

bb9: {
StorageDead(_2); // scope 0 at $DIR/issue-75439.rs:17:1: 17:2
return; // scope 0 at $DIR/issue-75439.rs:17:2: 17:2
}
}

0 comments on commit 1893161

Please sign in to comment.