1 // compile-flags: -Z panic-in-drop=abort -O -Z new-llvm-pass-manager=no
3 // Ensure that unwinding code paths are eliminated from the output after
6 // This test uses -Z new-llvm-pass-manager=no, because the expected optimization does not happen
7 // on targets using SEH exceptions (i.e. MSVC) anymore. The core issue is that Rust promises that
8 // the drop_in_place() function can't unwind, but implements it in a way that *can*, because we
9 // currently go out of our way to allow longjmps, which also use the unwinding mechanism on MSVC
10 // targets. We should either forbid longjmps, or not assume nounwind, making this optimization
11 // incompatible with the current behavior of running cleanuppads on longjmp unwinding.
13 // CHECK-NOT: {{(call|invoke).*}}should_not_appear_in_output
15 #![crate_type = "lib"]
19 pub struct ExternDrop;
20 impl Drop for ExternDrop {
23 // This call may potentially unwind.
33 struct AssertNeverDrop;
34 impl Drop for AssertNeverDrop {
37 // This call should be optimized away as unreachable.
39 fn should_not_appear_in_output();
42 should_not_appear_in_output();
48 pub fn normal_drop(x: ExternDrop) {
49 let guard = AssertNeverDrop;
55 pub fn indirect_drop(x: Box<dyn Any>) {
56 let guard = AssertNeverDrop;