Skip to content

Commit

Permalink
Add a MIR pre-codegen test for derived PartialOrd
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Mar 24, 2024
1 parent 548e14b commit 744c664
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/mir-opt/pre-codegen/derived_ord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// skip-filecheck
//@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=0

#![crate_type = "lib"]

#[derive(PartialOrd, PartialEq)]
pub struct MultiField(char, i16);

// EMIT_MIR derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// MIR for `<impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp` after PreCodegen

fn <impl at $DIR/derived_ord.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 mut _3: &char;
let mut _4: &char;
let mut _10: std::option::Option<std::cmp::Ordering>;
let mut _11: &i16;
let mut _12: &i16;
let _18: std::option::Option<std::cmp::Ordering>;
scope 1 {
debug cmp => _18;
}
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
debug self => _3;
debug other => _4;
let mut _9: std::cmp::Ordering;
scope 3 (inlined std::cmp::impls::<impl Ord for char>::cmp) {
debug self => _3;
debug other => _4;
let mut _5: char;
let mut _6: char;
let mut _7: bool;
let mut _8: bool;
}
}
scope 4 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
debug self => _11;
debug other => _12;
let mut _17: std::cmp::Ordering;
scope 5 (inlined std::cmp::impls::<impl Ord for i16>::cmp) {
debug self => _11;
debug other => _12;
let mut _13: i16;
let mut _14: i16;
let mut _15: bool;
let mut _16: bool;
}
}

bb0: {
StorageLive(_3);
_3 = &((*_1).0: char);
StorageLive(_4);
_4 = &((*_2).0: char);
StorageLive(_9);
StorageLive(_5);
StorageLive(_6);
StorageLive(_7);
_5 = ((*_1).0: char);
_6 = ((*_2).0: char);
_7 = Lt(_5, _6);
switchInt(move _7) -> [0: bb1, otherwise: bb10];
}

bb1: {
StorageLive(_8);
_8 = Eq(_5, _6);
switchInt(move _8) -> [0: bb2, otherwise: bb3];
}

bb2: {
_9 = const Greater;
StorageDead(_8);
StorageDead(_7);
StorageDead(_6);
StorageDead(_5);
_10 = Option::<std::cmp::Ordering>::Some(move _9);
StorageDead(_9);
StorageDead(_4);
StorageDead(_3);
goto -> bb11;
}

bb3: {
StorageDead(_8);
StorageDead(_7);
StorageDead(_6);
StorageDead(_5);
StorageDead(_9);
StorageDead(_4);
StorageDead(_3);
StorageLive(_11);
_11 = &((*_1).1: i16);
StorageLive(_12);
_12 = &((*_2).1: i16);
StorageLive(_17);
StorageLive(_13);
StorageLive(_14);
StorageLive(_15);
_13 = ((*_1).1: i16);
_14 = ((*_2).1: i16);
_15 = Lt(_13, _14);
switchInt(move _15) -> [0: bb4, otherwise: bb8];
}

bb4: {
StorageLive(_16);
_16 = Eq(_13, _14);
switchInt(move _16) -> [0: bb5, otherwise: bb6];
}

bb5: {
_17 = const Greater;
goto -> bb7;
}

bb6: {
_17 = const Equal;
goto -> bb7;
}

bb7: {
StorageDead(_16);
goto -> bb9;
}

bb8: {
_17 = const Less;
goto -> bb9;
}

bb9: {
StorageDead(_15);
StorageDead(_14);
StorageDead(_13);
_0 = Option::<std::cmp::Ordering>::Some(move _17);
StorageDead(_17);
StorageDead(_12);
StorageDead(_11);
goto -> bb12;
}

bb10: {
_9 = const Less;
StorageDead(_7);
StorageDead(_6);
StorageDead(_5);
_10 = Option::<std::cmp::Ordering>::Some(move _9);
StorageDead(_9);
StorageDead(_4);
StorageDead(_3);
goto -> bb11;
}

bb11: {
StorageLive(_18);
_18 = _10;
_0 = _10;
StorageDead(_18);
goto -> bb12;
}

bb12: {
return;
}
}

0 comments on commit 744c664

Please sign in to comment.