Skip to content

Commit c441640

Browse files
committed
Add a mir-opt test for *debug* MIR from derive(PartialOrd, Ord)
Because the follow-up commits will affect it, and the goal is to show how.
1 parent 63f6845 commit c441640

5 files changed

+206
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -Copt-level=0 -Zmir-opt-level=1 -Cdebuginfo=limited
2+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3+
4+
#![crate_type = "lib"]
5+
6+
#[derive(PartialOrd, Ord, PartialEq, Eq)]
7+
pub struct MultiField(char, i16);
8+
9+
// EMIT_MIR derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.mir
10+
// EMIT_MIR derived_ord_debug.{impl#1}-cmp.PreCodegen.after.mir
11+
12+
// CHECK-LABEL: partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering>
13+
// CHECK: = <char as PartialOrd>::partial_cmp(
14+
// CHECK: = <i16 as PartialOrd>::partial_cmp(
15+
16+
// CHECK-LABEL: cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering
17+
// CHECK: = <char as Ord>::cmp(
18+
// CHECK: = <i16 as Ord>::cmp(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// MIR for `<impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp` after PreCodegen
2+
3+
fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering> {
4+
debug self => _1;
5+
debug other => _2;
6+
let mut _0: std::option::Option<std::cmp::Ordering>;
7+
let _3: &char;
8+
let _4: &char;
9+
let mut _5: std::option::Option<std::cmp::Ordering>;
10+
let mut _6: isize;
11+
let mut _7: i8;
12+
let _8: &i16;
13+
let _9: &i16;
14+
scope 1 {
15+
debug cmp => _5;
16+
}
17+
18+
bb0: {
19+
_3 = &((*_1).0: char);
20+
_4 = &((*_2).0: char);
21+
_5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable];
22+
}
23+
24+
bb1: {
25+
_6 = discriminant(_5);
26+
switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6];
27+
}
28+
29+
bb2: {
30+
_7 = discriminant(((_5 as Some).0: std::cmp::Ordering));
31+
switchInt(move _7) -> [0: bb3, otherwise: bb4];
32+
}
33+
34+
bb3: {
35+
_8 = &((*_1).1: i16);
36+
_9 = &((*_2).1: i16);
37+
_0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind unreachable];
38+
}
39+
40+
bb4: {
41+
_0 = copy _5;
42+
goto -> bb5;
43+
}
44+
45+
bb5: {
46+
return;
47+
}
48+
49+
bb6: {
50+
unreachable;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// MIR for `<impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp` after PreCodegen
2+
3+
fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering> {
4+
debug self => _1;
5+
debug other => _2;
6+
let mut _0: std::option::Option<std::cmp::Ordering>;
7+
let _3: &char;
8+
let _4: &char;
9+
let mut _5: std::option::Option<std::cmp::Ordering>;
10+
let mut _6: isize;
11+
let mut _7: i8;
12+
let _8: &i16;
13+
let _9: &i16;
14+
scope 1 {
15+
debug cmp => _5;
16+
}
17+
18+
bb0: {
19+
_3 = &((*_1).0: char);
20+
_4 = &((*_2).0: char);
21+
_5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind continue];
22+
}
23+
24+
bb1: {
25+
_6 = discriminant(_5);
26+
switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6];
27+
}
28+
29+
bb2: {
30+
_7 = discriminant(((_5 as Some).0: std::cmp::Ordering));
31+
switchInt(move _7) -> [0: bb3, otherwise: bb4];
32+
}
33+
34+
bb3: {
35+
_8 = &((*_1).1: i16);
36+
_9 = &((*_2).1: i16);
37+
_0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind continue];
38+
}
39+
40+
bb4: {
41+
_0 = copy _5;
42+
goto -> bb5;
43+
}
44+
45+
bb5: {
46+
return;
47+
}
48+
49+
bb6: {
50+
unreachable;
51+
}
52+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// MIR for `<impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp` after PreCodegen
2+
3+
fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering {
4+
debug self => _1;
5+
debug other => _2;
6+
let mut _0: std::cmp::Ordering;
7+
let _3: &char;
8+
let _4: &char;
9+
let mut _5: std::cmp::Ordering;
10+
let mut _6: i8;
11+
let _7: &i16;
12+
let _8: &i16;
13+
scope 1 {
14+
debug cmp => _5;
15+
}
16+
17+
bb0: {
18+
_3 = &((*_1).0: char);
19+
_4 = &((*_2).0: char);
20+
_5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable];
21+
}
22+
23+
bb1: {
24+
_6 = discriminant(_5);
25+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
26+
}
27+
28+
bb2: {
29+
_7 = &((*_1).1: i16);
30+
_8 = &((*_2).1: i16);
31+
_0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind unreachable];
32+
}
33+
34+
bb3: {
35+
_0 = copy _5;
36+
goto -> bb4;
37+
}
38+
39+
bb4: {
40+
return;
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// MIR for `<impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp` after PreCodegen
2+
3+
fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering {
4+
debug self => _1;
5+
debug other => _2;
6+
let mut _0: std::cmp::Ordering;
7+
let _3: &char;
8+
let _4: &char;
9+
let mut _5: std::cmp::Ordering;
10+
let mut _6: i8;
11+
let _7: &i16;
12+
let _8: &i16;
13+
scope 1 {
14+
debug cmp => _5;
15+
}
16+
17+
bb0: {
18+
_3 = &((*_1).0: char);
19+
_4 = &((*_2).0: char);
20+
_5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind continue];
21+
}
22+
23+
bb1: {
24+
_6 = discriminant(_5);
25+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
26+
}
27+
28+
bb2: {
29+
_7 = &((*_1).1: i16);
30+
_8 = &((*_2).1: i16);
31+
_0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind continue];
32+
}
33+
34+
bb3: {
35+
_0 = copy _5;
36+
goto -> bb4;
37+
}
38+
39+
bb4: {
40+
return;
41+
}
42+
}

0 commit comments

Comments
 (0)