Skip to content

Commit 5862a00

Browse files
committed
Add test for -Z panic-in-drop=abort
1 parent a149bed commit 5862a00

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// compile-flags: -Z panic-in-drop=abort -O
2+
3+
// Ensure that unwinding code paths are eliminated from the output after
4+
// optimization.
5+
6+
#![crate_type = "lib"]
7+
use std::any::Any;
8+
use std::mem::forget;
9+
10+
pub struct ExternDrop;
11+
impl Drop for ExternDrop {
12+
#[inline(always)]
13+
fn drop(&mut self) {
14+
// This call may potentially unwind.
15+
extern "Rust" {
16+
fn extern_drop();
17+
}
18+
unsafe {
19+
extern_drop();
20+
}
21+
}
22+
}
23+
24+
struct AssertNeverDrop;
25+
impl Drop for AssertNeverDrop {
26+
#[inline(always)]
27+
fn drop(&mut self) {
28+
// This call should be optimized away as unreachable.
29+
extern "C" {
30+
fn should_not_appear_in_output();
31+
}
32+
unsafe {
33+
should_not_appear_in_output();
34+
}
35+
}
36+
}
37+
38+
// CHECK-LABEL: normal_drop
39+
// CHECK-NOT: should_not_appear_in_output
40+
#[no_mangle]
41+
pub fn normal_drop(x: ExternDrop) {
42+
let guard = AssertNeverDrop;
43+
drop(x);
44+
forget(guard);
45+
}
46+
47+
// CHECK-LABEL: indirect_drop
48+
// CHECK-NOT: should_not_appear_in_output
49+
#[no_mangle]
50+
pub fn indirect_drop(x: Box<dyn Any>) {
51+
let guard = AssertNeverDrop;
52+
drop(x);
53+
forget(guard);
54+
}

0 commit comments

Comments
 (0)