From 38bf66077173e7d1e030d0f808be96d2b16e8e70 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 16 Oct 2023 18:04:10 +0000 Subject: [PATCH] FileCheck box_expr.rs This check is made `needs-unwind`, as the panic=abort case is a strictly simpler version. --- ...main.ElaborateDrops.before.panic-abort.mir | 71 --------------- ...ain.ElaborateDrops.before.panic-unwind.mir | 71 --------------- .../mir-opt/box_expr.main.ElaborateDrops.diff | 89 +++++++++++++++++++ tests/mir-opt/box_expr.rs | 18 +++- 4 files changed, 104 insertions(+), 145 deletions(-) delete mode 100644 tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir delete mode 100644 tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir create mode 100644 tests/mir-opt/box_expr.main.ElaborateDrops.diff diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir deleted file mode 100644 index 1c7ef7f83456..000000000000 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir +++ /dev/null @@ -1,71 +0,0 @@ -// MIR for `main` before ElaborateDrops - -fn main() -> () { - let mut _0: (); - let _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let _6: (); - let mut _7: std::boxed::Box; - scope 1 { - debug x => _1; - } - scope 2 { - } - - bb0: { - StorageLive(_1); - _2 = SizeOf(S); - _3 = AlignOf(S); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind: bb9]; - } - - bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, S); - (*_5) = S::new() -> [return: bb2, unwind: bb8]; - } - - bb2: { - _1 = move _5; - drop(_5) -> [return: bb3, unwind: bb9]; - } - - bb3: { - StorageDead(_5); - StorageLive(_6); - StorageLive(_7); - _7 = move _1; - _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; - } - - bb4: { - StorageDead(_7); - StorageDead(_6); - _0 = const (); - drop(_1) -> [return: bb5, unwind: bb9]; - } - - bb5: { - StorageDead(_1); - return; - } - - bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate(cleanup)]; - } - - bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate(cleanup)]; - } - - bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate(cleanup)]; - } - - bb9 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir deleted file mode 100644 index 4ad1c2de1298..000000000000 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir +++ /dev/null @@ -1,71 +0,0 @@ -// MIR for `main` before ElaborateDrops - -fn main() -> () { - let mut _0: (); - let _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let _6: (); - let mut _7: std::boxed::Box; - scope 1 { - debug x => _1; - } - scope 2 { - } - - bb0: { - StorageLive(_1); - _2 = SizeOf(S); - _3 = AlignOf(S); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; - } - - bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, S); - (*_5) = S::new() -> [return: bb2, unwind: bb8]; - } - - bb2: { - _1 = move _5; - drop(_5) -> [return: bb3, unwind continue]; - } - - bb3: { - StorageDead(_5); - StorageLive(_6); - StorageLive(_7); - _7 = move _1; - _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; - } - - bb4: { - StorageDead(_7); - StorageDead(_6); - _0 = const (); - drop(_1) -> [return: bb5, unwind continue]; - } - - bb5: { - StorageDead(_1); - return; - } - - bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate(cleanup)]; - } - - bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate(cleanup)]; - } - - bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate(cleanup)]; - } - - bb9 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.diff b/tests/mir-opt/box_expr.main.ElaborateDrops.diff new file mode 100644 index 000000000000..88b12f19e64d --- /dev/null +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.diff @@ -0,0 +1,89 @@ +- // MIR for `main` before ElaborateDrops ++ // MIR for `main` after ElaborateDrops + + fn main() -> () { + let mut _0: (); + let _1: std::boxed::Box; + let mut _2: usize; + let mut _3: usize; + let mut _4: *mut u8; + let mut _5: std::boxed::Box; + let _6: (); + let mut _7: std::boxed::Box; ++ let mut _8: &mut std::boxed::Box; ++ let mut _9: (); + scope 1 { + debug x => _1; + } + scope 2 { + } + + bb0: { + StorageLive(_1); + _2 = SizeOf(S); + _3 = AlignOf(S); + _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_5); + _5 = ShallowInitBox(move _4, S); + (*_5) = S::new() -> [return: bb2, unwind: bb8]; + } + + bb2: { + _1 = move _5; +- drop(_5) -> [return: bb3, unwind continue]; ++ goto -> bb3; + } + + bb3: { + StorageDead(_5); + StorageLive(_6); + StorageLive(_7); + _7 = move _1; + _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; + } + + bb4: { + StorageDead(_7); + StorageDead(_6); + _0 = const (); +- drop(_1) -> [return: bb5, unwind continue]; ++ goto -> bb5; + } + + bb5: { + StorageDead(_1); + return; + } + + bb6 (cleanup): { +- drop(_7) -> [return: bb7, unwind terminate(cleanup)]; ++ goto -> bb7; + } + + bb7 (cleanup): { +- drop(_1) -> [return: bb9, unwind terminate(cleanup)]; ++ goto -> bb9; + } + + bb8 (cleanup): { +- drop(_5) -> [return: bb9, unwind terminate(cleanup)]; ++ goto -> bb11; + } + + bb9 (cleanup): { + resume; ++ } ++ ++ bb10 (cleanup): { ++ _8 = &mut _5; ++ _9 = as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)]; ++ } ++ ++ bb11 (cleanup): { ++ goto -> bb10; + } + } + diff --git a/tests/mir-opt/box_expr.rs b/tests/mir-opt/box_expr.rs index 30969a1704d0..0421e232ae4a 100644 --- a/tests/mir-opt/box_expr.rs +++ b/tests/mir-opt/box_expr.rs @@ -1,10 +1,22 @@ -// skip-filecheck -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +// unit-test: ElaborateDrops +// needs-unwind #![feature(rustc_attrs, stmt_expr_attributes)] -// EMIT_MIR box_expr.main.ElaborateDrops.before.mir +// EMIT_MIR box_expr.main.ElaborateDrops.diff fn main() { + // CHECK-LABEL: fn main( + // CHECK: [[box:_.*]] = ShallowInitBox( + // CHECK: [[ptr:_.*]] = ((([[box]].0: std::ptr::Unique).0: std::ptr::NonNull).0: *const S); + // CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]]; + // CHECK: [[ret]]: { + // CHECK: [[box2:_.*]] = move [[box]]; + // CHECK: [[box3:_.*]] = move [[box2]]; + // CHECK: std::mem::drop::>(move [[box3]]) + // CHECK: [[unwind]] (cleanup): { + // CHECK: [[boxref:_.*]] = &mut [[box]]; + // CHECK: as Drop>::drop(move [[boxref]]) + let x = #[rustc_box] Box::new(S::new()); drop(x);