Skip to content

Commit f037f79

Browse files
committed
Test catch_unwind vanishing
We execpt the try intrinsic to be a direct call if in -Cpanic=abort mode, and that catch_unwind optimizes out if calling a function that does not unwind.
1 parent e643804 commit f037f79

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/test/codegen/catch-unwind.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -O
2+
3+
#![crate_type = "lib"]
4+
5+
extern "C" {
6+
fn bar();
7+
}
8+
9+
// CHECK-LABEL: @foo
10+
#[no_mangle]
11+
pub unsafe fn foo() -> i32 {
12+
// CHECK: call void @bar
13+
// CHECK: ret i32 0
14+
std::panic::catch_unwind(|| {
15+
bar();
16+
0
17+
})
18+
.unwrap()
19+
}

src/test/codegen/try-panic-abort.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -C panic=abort -O
2+
3+
#![crate_type = "lib"]
4+
#![feature(unwind_attributes, core_intrinsics)]
5+
6+
extern "C" {
7+
#[unwind(allow)]
8+
fn bar(data: *mut u8);
9+
}
10+
11+
// CHECK-LABEL: @foo
12+
#[no_mangle]
13+
pub unsafe fn foo() -> i32 {
14+
// CHECK: call void @bar
15+
// CHECK: ret i32 0
16+
std::intrinsics::r#try(|x| bar(x), 0 as *mut u8, 0 as *mut u8)
17+
}

0 commit comments

Comments
 (0)