1 // compile-flags: -Z panic-in-drop=abort -O
4 // Ensure that unwinding code paths are eliminated from the output after
7 // This test uses ignore-msvc, because the expected optimization does not happen on targets using
8 // SEH exceptions with the new LLVM pass manager anymore, see
9 // https://github.com/llvm/llvm-project/issues/51311. The core issue is that Rust promises that
10 // the drop_in_place() function can't unwind, but implements it in a way that *can*, because we
11 // currently go out of our way to allow longjmps, which also use the unwinding mechanism on MSVC
12 // targets. We should either forbid longjmps, or not assume nounwind, making this optimization
13 // incompatible with the current behavior of running cleanuppads on longjmp unwinding.
15 // CHECK-NOT: {{(call|invoke).*}}should_not_appear_in_output
17 #![crate_type = "lib"]
21 pub struct ExternDrop;
22 impl Drop for ExternDrop {
25 // This call may potentially unwind.
35 struct AssertNeverDrop;
36 impl Drop for AssertNeverDrop {
39 // This call should be optimized away as unreachable.
41 fn should_not_appear_in_output();
44 should_not_appear_in_output();
50 pub fn normal_drop(x: ExternDrop) {
51 let guard = AssertNeverDrop;
57 pub fn indirect_drop(x: Box<dyn Any>) {
58 let guard = AssertNeverDrop;