summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-12-18 21:54:50 +0000
committerJosh Stone <jistone@redhat.com>2025-01-02 14:28:32 -0800
commit3113133cb7321abd41c9af2a74af1d75f75d60ab (patch)
tree75400a90cf4f3c79875d072285b0d850150c9312
parent9d0471549526f8e17c9a81f3dcc26f7d4ceee03f (diff)
downloadrust-3113133cb7321abd41c9af2a74af1d75f75d60ab.tar.gz
rust-3113133cb7321abd41c9af2a74af1d75f75d60ab.zip
Add a failing test
(cherry picked from commit 2e57394d8004b155c6f74ca4e2a1106dedfcccc4)
-rw-r--r--tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir183
-rw-r--r--tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir183
-rw-r--r--tests/mir-opt/tail_expr_drop_order_unwind.rs36
3 files changed, 402 insertions, 0 deletions
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<OtherDrop, ()>;
+    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 = <Guard as Clone>::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<OtherDrop, ()>;
+    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 = <Guard as Clone>::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<OtherDrop, ()> {
+    panic!("Method 2 panics!");
+}