diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-07-25 11:16:14 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-08-03 17:30:40 -0700 |
| commit | c441640f0eab5abcdf5004aacdc5e4830c3f1552 (patch) | |
| tree | da4ecde5dd97a2fe588206f8da02b61f0e7a94e7 /tests/mir-opt | |
| parent | 63f6845e570305a92eaf855897768617366164d6 (diff) | |
| download | rust-c441640f0eab5abcdf5004aacdc5e4830c3f1552.tar.gz rust-c441640f0eab5abcdf5004aacdc5e4830c3f1552.zip | |
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.
Diffstat (limited to 'tests/mir-opt')
5 files changed, 206 insertions, 0 deletions
diff --git a/tests/mir-opt/pre-codegen/derived_ord_debug.rs b/tests/mir-opt/pre-codegen/derived_ord_debug.rs new file mode 100644 index 00000000000..1d6a884cee4 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord_debug.rs @@ -0,0 +1,18 @@ +//@ compile-flags: -Copt-level=0 -Zmir-opt-level=1 -Cdebuginfo=limited +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +#![crate_type = "lib"] + +#[derive(PartialOrd, Ord, PartialEq, Eq)] +pub struct MultiField(char, i16); + +// EMIT_MIR derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.mir +// EMIT_MIR derived_ord_debug.{impl#1}-cmp.PreCodegen.after.mir + +// CHECK-LABEL: partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering> +// CHECK: = <char as PartialOrd>::partial_cmp( +// CHECK: = <i16 as PartialOrd>::partial_cmp( + +// CHECK-LABEL: cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering +// CHECK: = <char as Ord>::cmp( +// CHECK: = <i16 as Ord>::cmp( diff --git a/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-abort.mir new file mode 100644 index 00000000000..9fc8da3a112 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-abort.mir @@ -0,0 +1,52 @@ +// MIR for `<impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp` after PreCodegen + +fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering> { + debug self => _1; + debug other => _2; + let mut _0: std::option::Option<std::cmp::Ordering>; + let _3: &char; + let _4: &char; + let mut _5: std::option::Option<std::cmp::Ordering>; + let mut _6: isize; + let mut _7: i8; + let _8: &i16; + let _9: &i16; + scope 1 { + debug cmp => _5; + } + + bb0: { + _3 = &((*_1).0: char); + _4 = &((*_2).0: char); + _5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable]; + } + + bb1: { + _6 = discriminant(_5); + switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6]; + } + + bb2: { + _7 = discriminant(((_5 as Some).0: std::cmp::Ordering)); + switchInt(move _7) -> [0: bb3, otherwise: bb4]; + } + + bb3: { + _8 = &((*_1).1: i16); + _9 = &((*_2).1: i16); + _0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind unreachable]; + } + + bb4: { + _0 = copy _5; + goto -> bb5; + } + + bb5: { + return; + } + + bb6: { + unreachable; + } +} diff --git a/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-unwind.mir new file mode 100644 index 00000000000..29cc5415076 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-unwind.mir @@ -0,0 +1,52 @@ +// MIR for `<impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp` after PreCodegen + +fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering> { + debug self => _1; + debug other => _2; + let mut _0: std::option::Option<std::cmp::Ordering>; + let _3: &char; + let _4: &char; + let mut _5: std::option::Option<std::cmp::Ordering>; + let mut _6: isize; + let mut _7: i8; + let _8: &i16; + let _9: &i16; + scope 1 { + debug cmp => _5; + } + + bb0: { + _3 = &((*_1).0: char); + _4 = &((*_2).0: char); + _5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind continue]; + } + + bb1: { + _6 = discriminant(_5); + switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6]; + } + + bb2: { + _7 = discriminant(((_5 as Some).0: std::cmp::Ordering)); + switchInt(move _7) -> [0: bb3, otherwise: bb4]; + } + + bb3: { + _8 = &((*_1).1: i16); + _9 = &((*_2).1: i16); + _0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind continue]; + } + + bb4: { + _0 = copy _5; + goto -> bb5; + } + + bb5: { + return; + } + + bb6: { + unreachable; + } +} diff --git a/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-abort.mir new file mode 100644 index 00000000000..66d96021aa9 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-abort.mir @@ -0,0 +1,42 @@ +// MIR for `<impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp` after PreCodegen + +fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering { + debug self => _1; + debug other => _2; + let mut _0: std::cmp::Ordering; + let _3: &char; + let _4: &char; + let mut _5: std::cmp::Ordering; + let mut _6: i8; + let _7: &i16; + let _8: &i16; + scope 1 { + debug cmp => _5; + } + + bb0: { + _3 = &((*_1).0: char); + _4 = &((*_2).0: char); + _5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable]; + } + + bb1: { + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _7 = &((*_1).1: i16); + _8 = &((*_2).1: i16); + _0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind unreachable]; + } + + bb3: { + _0 = copy _5; + goto -> bb4; + } + + bb4: { + return; + } +} diff --git a/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-unwind.mir new file mode 100644 index 00000000000..2dcba6195f7 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-unwind.mir @@ -0,0 +1,42 @@ +// MIR for `<impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp` after PreCodegen + +fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering { + debug self => _1; + debug other => _2; + let mut _0: std::cmp::Ordering; + let _3: &char; + let _4: &char; + let mut _5: std::cmp::Ordering; + let mut _6: i8; + let _7: &i16; + let _8: &i16; + scope 1 { + debug cmp => _5; + } + + bb0: { + _3 = &((*_1).0: char); + _4 = &((*_2).0: char); + _5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind continue]; + } + + bb1: { + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _7 = &((*_1).1: i16); + _8 = &((*_2).1: i16); + _0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind continue]; + } + + bb3: { + _0 = copy _5; + goto -> bb4; + } + + bb4: { + return; + } +} |
