diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-10-16 19:26:04 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-10-19 15:51:54 +0000 |
| commit | ddc328c2f1ba2fb90206f9eecf39fa8b78bc140f (patch) | |
| tree | 418e0e05237f79c4fff1fe0badaacb666f413f61 /tests/mir-opt/instsimplify | |
| parent | 5453a4f056e2f5c3da85bebca1de95be32177385 (diff) | |
FileCheck combine_clone_of_primitives.
Diffstat (limited to 'tests/mir-opt/instsimplify')
3 files changed, 162 insertions, 0 deletions
diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs b/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs new file mode 100644 index 00000000000..2adbe778d23 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.rs @@ -0,0 +1,24 @@ +// unit-test: InstSimplify +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +// EMIT_MIR combine_clone_of_primitives.{impl#0}-clone.InstSimplify.diff +#[derive(Clone)] +struct MyThing<T> { + v: T, + i: u64, + a: [f32; 3], +} + +// CHECK-LABEL: ::clone( +// CHECK: <T as Clone>::clone( +// CHECK-NOT: <u64 as Clone>::clone( +// CHECK-NOT: <[f32; 3] as Clone>::clone( + +fn main() { + let x = MyThing::<i16> { v: 2, i: 3, a: [0.0; 3] }; + let y = x.clone(); + + assert_eq!(y.v, 2); + assert_eq!(y.i, 3); + assert_eq!(y.a, [0.0; 3]); +} diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff new file mode 100644 index 00000000000..48586f8b334 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-abort.diff @@ -0,0 +1,65 @@ +- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` before InstSimplify ++ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` after InstSimplify + + fn <impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone(_1: &MyThing<T>) -> MyThing<T> { + debug self => _1; + let mut _0: MyThing<T>; + let mut _2: T; + let mut _3: &T; + let _4: &T; + let mut _5: u64; + let mut _6: &u64; + let _7: &u64; + let mut _8: [f32; 3]; + let mut _9: &[f32; 3]; + let _10: &[f32; 3]; + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = &((*_1).0: T); +- _3 = &(*_4); ++ _3 = _4; + _2 = <T as Clone>::clone(move _3) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_3); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = &((*_1).1: u64); +- _6 = &(*_7); +- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind unreachable]; ++ _6 = _7; ++ _5 = (*_6); ++ goto -> bb2; + } + + bb2: { + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = &((*_1).2: [f32; 3]); +- _9 = &(*_10); +- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind unreachable]; ++ _9 = _10; ++ _8 = (*_9); ++ goto -> bb3; + } + + bb3: { + StorageDead(_9); + _0 = MyThing::<T> { v: move _2, i: move _5, a: move _8 }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_2); + StorageDead(_10); + StorageDead(_7); + StorageDead(_4); + return; + } + } + diff --git a/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff new file mode 100644 index 00000000000..a57266e9c12 --- /dev/null +++ b/tests/mir-opt/instsimplify/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff @@ -0,0 +1,73 @@ +- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` before InstSimplify ++ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone` after InstSimplify + + fn <impl at $DIR/combine_clone_of_primitives.rs:5:10: 5:15>::clone(_1: &MyThing<T>) -> MyThing<T> { + debug self => _1; + let mut _0: MyThing<T>; + let mut _2: T; + let mut _3: &T; + let _4: &T; + let mut _5: u64; + let mut _6: &u64; + let _7: &u64; + let mut _8: [f32; 3]; + let mut _9: &[f32; 3]; + let _10: &[f32; 3]; + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + _4 = &((*_1).0: T); +- _3 = &(*_4); ++ _3 = _4; + _2 = <T as Clone>::clone(move _3) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_3); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = &((*_1).1: u64); +- _6 = &(*_7); +- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind: bb4]; ++ _6 = _7; ++ _5 = (*_6); ++ goto -> bb2; + } + + bb2: { + StorageDead(_6); + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = &((*_1).2: [f32; 3]); +- _9 = &(*_10); +- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind: bb4]; ++ _9 = _10; ++ _8 = (*_9); ++ goto -> bb3; + } + + bb3: { + StorageDead(_9); + _0 = MyThing::<T> { v: move _2, i: move _5, a: move _8 }; + StorageDead(_8); + StorageDead(_5); + StorageDead(_2); + StorageDead(_10); + StorageDead(_7); + StorageDead(_4); + return; + } + + bb4 (cleanup): { + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; + } + + bb5 (cleanup): { + resume; + } + } + |
