Skip to content

Commit 557265d

Browse files
committed
Do checked_ops for each panic strategy
1 parent d4344e6 commit 557265d

5 files changed

+153
-41
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// MIR for `checked_shl` after PreCodegen
2+
3+
fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
4+
debug x => _1;
5+
debug rhs => _2;
6+
let mut _0: std::option::Option<u32>;
7+
scope 1 (inlined core::num::<impl u32>::checked_shl) {
8+
debug self => _1;
9+
debug rhs => _2;
10+
let mut _6: bool;
11+
scope 2 {
12+
debug a => _4;
13+
debug b => _5;
14+
}
15+
scope 3 (inlined core::num::<impl u32>::overflowing_shl) {
16+
let mut _4: u32;
17+
let mut _5: bool;
18+
scope 4 (inlined core::num::<impl u32>::wrapping_shl) {
19+
let mut _3: u32;
20+
scope 5 (inlined core::num::<impl u32>::unchecked_shl) {
21+
}
22+
}
23+
}
24+
}
25+
26+
bb0: {
27+
StorageLive(_4);
28+
StorageLive(_5);
29+
StorageLive(_3);
30+
_3 = BitAnd(_2, const 31_u32);
31+
_4 = ShlUnchecked(_1, _3);
32+
StorageDead(_3);
33+
_5 = Ge(_2, const core::num::<impl u32>::BITS);
34+
StorageLive(_6);
35+
_6 = unlikely(move _5) -> [return: bb1, unwind unreachable];
36+
}
37+
38+
bb1: {
39+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
40+
}
41+
42+
bb2: {
43+
_0 = Option::<u32>::Some(_4);
44+
goto -> bb4;
45+
}
46+
47+
bb3: {
48+
_0 = const Option::<u32>::None;
49+
goto -> bb4;
50+
}
51+
52+
bb4: {
53+
StorageDead(_6);
54+
StorageDead(_5);
55+
StorageDead(_4);
56+
return;
57+
}
58+
}
59+
60+
ALLOC0 (size: 8, align: 4) {
61+
00 00 00 00 __ __ __ __ │ ....░░░░
62+
}

tests/mir-opt/pre-codegen/checked_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// skip-filecheck
22
//@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
3-
//@ needs-unwind
3+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
44

55
#![crate_type = "lib"]
66
#![feature(step_trait)]

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir renamed to tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
77
scope 1 (inlined <u32 as Step>::forward) {
88
debug start => _1;
99
debug n => _2;
10-
let mut _8: u32;
1110
scope 2 {
1211
}
1312
scope 3 (inlined <u32 as Step>::forward_checked) {
1413
scope 4 {
1514
scope 6 (inlined core::num::<impl u32>::checked_add) {
16-
let mut _7: bool;
15+
let mut _6: bool;
1716
scope 7 {
1817
}
1918
scope 8 (inlined core::num::<impl u32>::overflowing_add) {
20-
let mut _5: (u32, bool);
21-
let _6: bool;
19+
let mut _4: (u32, bool);
20+
let _5: bool;
2221
scope 9 {
2322
}
2423
}
2524
}
2625
}
2726
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u32>::try_from) {
28-
let mut _3: bool;
29-
let mut _4: u32;
27+
let mut _3: u32;
3028
}
3129
}
3230
scope 10 (inlined Option::<u32>::is_none) {
@@ -38,55 +36,36 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
3836
}
3937

4038
bb0: {
41-
StorageLive(_4);
4239
StorageLive(_3);
43-
_3 = Gt(_2, const 4294967295_usize);
44-
switchInt(move _3) -> [0: bb1, otherwise: bb5];
40+
_3 = _2 as u32 (IntToInt);
41+
StorageLive(_5);
42+
StorageLive(_4);
43+
_4 = CheckedAdd(_1, _3);
44+
_5 = (_4.1: bool);
45+
StorageDead(_4);
46+
StorageLive(_6);
47+
_6 = unlikely(move _5) -> [return: bb1, unwind unreachable];
4548
}
4649

4750
bb1: {
48-
_4 = _2 as u32 (IntToInt);
49-
StorageDead(_3);
50-
StorageLive(_6);
51-
StorageLive(_5);
52-
_5 = CheckedAdd(_1, _4);
53-
_6 = (_5.1: bool);
54-
StorageDead(_5);
55-
StorageLive(_7);
56-
_7 = unlikely(move _6) -> [return: bb2, unwind unreachable];
51+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
5752
}
5853

5954
bb2: {
60-
switchInt(move _7) -> [0: bb3, otherwise: bb4];
55+
StorageDead(_6);
56+
StorageDead(_5);
57+
goto -> bb4;
6158
}
6259

6360
bb3: {
64-
StorageDead(_7);
6561
StorageDead(_6);
66-
goto -> bb7;
62+
StorageDead(_5);
63+
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u32>::MAX, const 1_u32) -> [success: bb4, unwind unreachable];
6764
}
6865

6966
bb4: {
70-
StorageDead(_7);
71-
StorageDead(_6);
72-
goto -> bb6;
73-
}
74-
75-
bb5: {
67+
_0 = Add(_1, _3);
7668
StorageDead(_3);
77-
goto -> bb6;
78-
}
79-
80-
bb6: {
81-
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u32>::MAX, const 1_u32) -> [success: bb7, unwind continue];
82-
}
83-
84-
bb7: {
85-
StorageLive(_8);
86-
_8 = _2 as u32 (IntToInt);
87-
_0 = Add(_1, _8);
88-
StorageDead(_8);
89-
StorageDead(_4);
9069
return;
9170
}
9271
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// MIR for `step_forward` after PreCodegen
2+
3+
fn step_forward(_1: u32, _2: usize) -> u32 {
4+
debug x => _1;
5+
debug n => _2;
6+
let mut _0: u32;
7+
scope 1 (inlined <u32 as Step>::forward) {
8+
debug start => _1;
9+
debug n => _2;
10+
scope 2 {
11+
}
12+
scope 3 (inlined <u32 as Step>::forward_checked) {
13+
scope 4 {
14+
scope 6 (inlined core::num::<impl u32>::checked_add) {
15+
let mut _6: bool;
16+
scope 7 {
17+
}
18+
scope 8 (inlined core::num::<impl u32>::overflowing_add) {
19+
let mut _4: (u32, bool);
20+
let _5: bool;
21+
scope 9 {
22+
}
23+
}
24+
}
25+
}
26+
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u32>::try_from) {
27+
let mut _3: u32;
28+
}
29+
}
30+
scope 10 (inlined Option::<u32>::is_none) {
31+
scope 11 (inlined Option::<u32>::is_some) {
32+
}
33+
}
34+
scope 12 (inlined core::num::<impl u32>::wrapping_add) {
35+
}
36+
}
37+
38+
bb0: {
39+
StorageLive(_3);
40+
_3 = _2 as u32 (IntToInt);
41+
StorageLive(_5);
42+
StorageLive(_4);
43+
_4 = CheckedAdd(_1, _3);
44+
_5 = (_4.1: bool);
45+
StorageDead(_4);
46+
StorageLive(_6);
47+
_6 = unlikely(move _5) -> [return: bb1, unwind unreachable];
48+
}
49+
50+
bb1: {
51+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
52+
}
53+
54+
bb2: {
55+
StorageDead(_6);
56+
StorageDead(_5);
57+
goto -> bb4;
58+
}
59+
60+
bb3: {
61+
StorageDead(_6);
62+
StorageDead(_5);
63+
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u32>::MAX, const 1_u32) -> [success: bb4, unwind continue];
64+
}
65+
66+
bb4: {
67+
_0 = Add(_1, _3);
68+
StorageDead(_3);
69+
return;
70+
}
71+
}

0 commit comments

Comments
 (0)