forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#123332 - Nadrieril:testkind-never, r=matthewj…
…asper never patterns: lower never patterns to `Unreachable` in MIR This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later. r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
- Loading branch information
Showing
16 changed files
with
315 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// MIR for `opt1` after SimplifyCfg-initial | ||
|
||
fn opt1(_1: &Result<u32, Void>) -> &u32 { | ||
debug res => _1; | ||
let mut _0: &u32; | ||
let mut _2: isize; | ||
let _3: &u32; | ||
let mut _4: !; | ||
let mut _5: (); | ||
scope 1 { | ||
debug x => _3; | ||
} | ||
|
||
bb0: { | ||
PlaceMention(_1); | ||
_2 = discriminant((*_1)); | ||
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1]; | ||
} | ||
|
||
bb1: { | ||
FakeRead(ForMatchedPlace(None), _1); | ||
unreachable; | ||
} | ||
|
||
bb2: { | ||
falseEdge -> [real: bb4, imaginary: bb3]; | ||
} | ||
|
||
bb3: { | ||
FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); | ||
unreachable; | ||
} | ||
|
||
bb4: { | ||
StorageLive(_3); | ||
_3 = &(((*_1) as Ok).0: u32); | ||
_0 = &(*_3); | ||
StorageDead(_3); | ||
return; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/mir-opt/building/match/never_patterns.opt2.SimplifyCfg-initial.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// MIR for `opt2` after SimplifyCfg-initial | ||
|
||
fn opt2(_1: &Result<u32, Void>) -> &u32 { | ||
debug res => _1; | ||
let mut _0: &u32; | ||
let mut _2: isize; | ||
let _3: &u32; | ||
scope 1 { | ||
debug x => _3; | ||
} | ||
|
||
bb0: { | ||
PlaceMention(_1); | ||
_2 = discriminant((*_1)); | ||
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1]; | ||
} | ||
|
||
bb1: { | ||
FakeRead(ForMatchedPlace(None), _1); | ||
unreachable; | ||
} | ||
|
||
bb2: { | ||
StorageLive(_3); | ||
_3 = &(((*_1) as Ok).0: u32); | ||
_0 = &(*_3); | ||
StorageDead(_3); | ||
return; | ||
} | ||
|
||
bb3: { | ||
FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); | ||
unreachable; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/mir-opt/building/match/never_patterns.opt3.SimplifyCfg-initial.after.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// MIR for `opt3` after SimplifyCfg-initial | ||
|
||
fn opt3(_1: &Result<u32, Void>) -> &u32 { | ||
debug res => _1; | ||
let mut _0: &u32; | ||
let mut _2: isize; | ||
let _3: &u32; | ||
scope 1 { | ||
debug x => _3; | ||
} | ||
|
||
bb0: { | ||
PlaceMention(_1); | ||
_2 = discriminant((*_1)); | ||
switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1]; | ||
} | ||
|
||
bb1: { | ||
FakeRead(ForMatchedPlace(None), _1); | ||
unreachable; | ||
} | ||
|
||
bb2: { | ||
FakeRead(ForMatchedPlace(None), (((*_1) as Err).0: Void)); | ||
unreachable; | ||
} | ||
|
||
bb3: { | ||
StorageLive(_3); | ||
_3 = &(((*_1) as Ok).0: u32); | ||
_0 = &(*_3); | ||
StorageDead(_3); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![feature(never_patterns)] | ||
#![allow(incomplete_features)] | ||
|
||
enum Void {} | ||
|
||
// EMIT_MIR never_patterns.opt1.SimplifyCfg-initial.after.mir | ||
fn opt1(res: &Result<u32, Void>) -> &u32 { | ||
// CHECK-LABEL: fn opt1( | ||
// CHECK: bb0: { | ||
// CHECK-NOT: {{bb.*}}: { | ||
// CHECK: return; | ||
match res { | ||
Ok(x) => x, | ||
Err(!), | ||
} | ||
} | ||
|
||
// EMIT_MIR never_patterns.opt2.SimplifyCfg-initial.after.mir | ||
fn opt2(res: &Result<u32, Void>) -> &u32 { | ||
// CHECK-LABEL: fn opt2( | ||
// CHECK: bb0: { | ||
// CHECK-NOT: {{bb.*}}: { | ||
// CHECK: return; | ||
match res { | ||
Ok(x) | Err(!) => x, | ||
} | ||
} | ||
|
||
// EMIT_MIR never_patterns.opt3.SimplifyCfg-initial.after.mir | ||
fn opt3(res: &Result<u32, Void>) -> &u32 { | ||
// CHECK-LABEL: fn opt3( | ||
// CHECK: bb0: { | ||
// CHECK-NOT: {{bb.*}}: { | ||
// CHECK: return; | ||
match res { | ||
Err(!) | Ok(x) => x, | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!(opt1(&Ok(0)), &0); | ||
assert_eq!(opt2(&Ok(0)), &0); | ||
assert_eq!(opt3(&Ok(0)), &0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.