From 2e57394d8004b155c6f74ca4e2a1106dedfcccc4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 18 Dec 2024 21:54:50 +0000 Subject: [PATCH] Add a failing test --- ...hod_1.ElaborateDrops.after.panic-abort.mir | 183 ++++++++++++++++++ ...od_1.ElaborateDrops.after.panic-unwind.mir | 183 ++++++++++++++++++ tests/mir-opt/tail_expr_drop_order_unwind.rs | 36 ++++ 3 files changed, 402 insertions(+) create mode 100644 tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir create mode 100644 tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir create mode 100644 tests/mir-opt/tail_expr_drop_order_unwind.rs diff --git a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir new file mode 100644 index 00000000000..54bedfdc0af --- /dev/null +++ b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir @@ -0,0 +1,183 @@ +// MIR for `method_1` after ElaborateDrops + +fn method_1(_1: Guard) -> () { + debug g => _1; + let mut _0: (); + let mut _2: std::result::Result; + let mut _3: &Guard; + let _4: &Guard; + let _5: Guard; + let mut _6: &Guard; + let mut _7: isize; + let _8: OtherDrop; + let _9: (); + let mut _10: bool; + let mut _11: bool; + let mut _12: isize; + let mut _13: isize; + let mut _14: isize; + scope 1 { + debug other_drop => _8; + } + scope 2 { + debug err => _9; + } + + bb0: { + _11 = const false; + _10 = const false; + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + _6 = &_1; + _5 = ::clone(move _6) -> [return: bb1, unwind: bb16]; + } + + bb1: { + _11 = const true; + StorageDead(_6); + _4 = &_5; + _3 = &(*_4); + _2 = method_2(move _3) -> [return: bb2, unwind: bb14]; + } + + bb2: { + _10 = const true; + StorageDead(_3); + PlaceMention(_2); + _7 = discriminant(_2); + switchInt(move _7) -> [0: bb5, 1: bb4, otherwise: bb3]; + } + + bb3: { + unreachable; + } + + bb4: { + StorageLive(_9); + _9 = copy ((_2 as Err).0: ()); + _0 = const (); + StorageDead(_9); + goto -> bb7; + } + + bb5: { + StorageLive(_8); + _8 = move ((_2 as Ok).0: OtherDrop); + _0 = const (); + drop(_8) -> [return: bb6, unwind: bb11]; + } + + bb6: { + StorageDead(_8); + goto -> bb7; + } + + bb7: { + backward incompatible drop(_2); + backward incompatible drop(_5); + goto -> bb24; + } + + bb8: { + drop(_5) -> [return: bb9, unwind: bb16]; + } + + bb9: { + _11 = const false; + StorageDead(_5); + StorageDead(_4); + _10 = const false; + StorageDead(_2); + drop(_1) -> [return: bb10, unwind: bb17]; + } + + bb10: { + return; + } + + bb11 (cleanup): { + goto -> bb28; + } + + bb12 (cleanup): { + drop(_5) -> [return: bb13, unwind terminate(cleanup)]; + } + + bb13 (cleanup): { + goto -> bb15; + } + + bb14 (cleanup): { + drop(_5) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + goto -> bb30; + } + + bb16 (cleanup): { + drop(_1) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + resume; + } + + bb18: { + goto -> bb8; + } + + bb19 (cleanup): { + goto -> bb15; + } + + bb20 (cleanup): { + goto -> bb15; + } + + bb21: { + goto -> bb18; + } + + bb22: { + goto -> bb18; + } + + bb23 (cleanup): { + goto -> bb15; + } + + bb24: { + _12 = discriminant(_2); + switchInt(move _12) -> [0: bb21, otherwise: bb22]; + } + + bb25 (cleanup): { + _13 = discriminant(_2); + switchInt(move _13) -> [0: bb19, otherwise: bb23]; + } + + bb26 (cleanup): { + goto -> bb12; + } + + bb27 (cleanup): { + goto -> bb12; + } + + bb28 (cleanup): { + _14 = discriminant(_2); + switchInt(move _14) -> [0: bb26, otherwise: bb27]; + } + + bb29 (cleanup): { + drop(_5) -> [return: bb16, unwind terminate(cleanup)]; + } + + bb30 (cleanup): { + switchInt(copy _11) -> [0: bb16, otherwise: bb29]; + } +} diff --git a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir new file mode 100644 index 00000000000..54bedfdc0af --- /dev/null +++ b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir @@ -0,0 +1,183 @@ +// MIR for `method_1` after ElaborateDrops + +fn method_1(_1: Guard) -> () { + debug g => _1; + let mut _0: (); + let mut _2: std::result::Result; + let mut _3: &Guard; + let _4: &Guard; + let _5: Guard; + let mut _6: &Guard; + let mut _7: isize; + let _8: OtherDrop; + let _9: (); + let mut _10: bool; + let mut _11: bool; + let mut _12: isize; + let mut _13: isize; + let mut _14: isize; + scope 1 { + debug other_drop => _8; + } + scope 2 { + debug err => _9; + } + + bb0: { + _11 = const false; + _10 = const false; + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + _6 = &_1; + _5 = ::clone(move _6) -> [return: bb1, unwind: bb16]; + } + + bb1: { + _11 = const true; + StorageDead(_6); + _4 = &_5; + _3 = &(*_4); + _2 = method_2(move _3) -> [return: bb2, unwind: bb14]; + } + + bb2: { + _10 = const true; + StorageDead(_3); + PlaceMention(_2); + _7 = discriminant(_2); + switchInt(move _7) -> [0: bb5, 1: bb4, otherwise: bb3]; + } + + bb3: { + unreachable; + } + + bb4: { + StorageLive(_9); + _9 = copy ((_2 as Err).0: ()); + _0 = const (); + StorageDead(_9); + goto -> bb7; + } + + bb5: { + StorageLive(_8); + _8 = move ((_2 as Ok).0: OtherDrop); + _0 = const (); + drop(_8) -> [return: bb6, unwind: bb11]; + } + + bb6: { + StorageDead(_8); + goto -> bb7; + } + + bb7: { + backward incompatible drop(_2); + backward incompatible drop(_5); + goto -> bb24; + } + + bb8: { + drop(_5) -> [return: bb9, unwind: bb16]; + } + + bb9: { + _11 = const false; + StorageDead(_5); + StorageDead(_4); + _10 = const false; + StorageDead(_2); + drop(_1) -> [return: bb10, unwind: bb17]; + } + + bb10: { + return; + } + + bb11 (cleanup): { + goto -> bb28; + } + + bb12 (cleanup): { + drop(_5) -> [return: bb13, unwind terminate(cleanup)]; + } + + bb13 (cleanup): { + goto -> bb15; + } + + bb14 (cleanup): { + drop(_5) -> [return: bb15, unwind terminate(cleanup)]; + } + + bb15 (cleanup): { + goto -> bb30; + } + + bb16 (cleanup): { + drop(_1) -> [return: bb17, unwind terminate(cleanup)]; + } + + bb17 (cleanup): { + resume; + } + + bb18: { + goto -> bb8; + } + + bb19 (cleanup): { + goto -> bb15; + } + + bb20 (cleanup): { + goto -> bb15; + } + + bb21: { + goto -> bb18; + } + + bb22: { + goto -> bb18; + } + + bb23 (cleanup): { + goto -> bb15; + } + + bb24: { + _12 = discriminant(_2); + switchInt(move _12) -> [0: bb21, otherwise: bb22]; + } + + bb25 (cleanup): { + _13 = discriminant(_2); + switchInt(move _13) -> [0: bb19, otherwise: bb23]; + } + + bb26 (cleanup): { + goto -> bb12; + } + + bb27 (cleanup): { + goto -> bb12; + } + + bb28 (cleanup): { + _14 = discriminant(_2); + switchInt(move _14) -> [0: bb26, otherwise: bb27]; + } + + bb29 (cleanup): { + drop(_5) -> [return: bb16, unwind terminate(cleanup)]; + } + + bb30 (cleanup): { + switchInt(copy _11) -> [0: bb16, otherwise: bb29]; + } +} diff --git a/tests/mir-opt/tail_expr_drop_order_unwind.rs b/tests/mir-opt/tail_expr_drop_order_unwind.rs new file mode 100644 index 00000000000..b67b3580875 --- /dev/null +++ b/tests/mir-opt/tail_expr_drop_order_unwind.rs @@ -0,0 +1,36 @@ +// skip-filecheck +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// EMIT_MIR tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.mir + +#![deny(tail_expr_drop_order)] + +use std::backtrace::Backtrace; + +#[derive(Clone)] +struct Guard; +impl Drop for Guard { + fn drop(&mut self) { + println!("Drop!"); + } +} + +#[derive(Clone)] +struct OtherDrop; +impl Drop for OtherDrop { + fn drop(&mut self) { + println!("Drop!"); + } +} + +fn method_1(g: Guard) { + match method_2(&g.clone()) { + Ok(other_drop) => { + // repro needs something else being dropped too. + }, + Err(err) => {}, + } +} + +fn method_2(_: &Guard) -> Result { + panic!("Method 2 panics!"); +}