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.
This commit is contained in:
Amanieu d'Antras 2019-12-26 10:37:48 -05:00
parent 1920f817ca
commit 919c5fe6b9
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,19 @@
// compile-flags: -O
#![crate_type = "lib"]
extern "C" {
fn bar();
}
// CHECK-LABEL: @foo
#[no_mangle]
pub unsafe fn foo() -> i32 {
// CHECK: call void @bar
// CHECK: ret i32 0
std::panic::catch_unwind(|| {
bar();
0
})
.unwrap()
}

View file

@ -0,0 +1,17 @@
// compile-flags: -C panic=abort -O
#![crate_type = "lib"]
#![feature(unwind_attributes, core_intrinsics)]
extern "C" {
#[unwind(allow)]
fn bar(data: *mut u8);
}
// CHECK-LABEL: @foo
#[no_mangle]
pub unsafe fn foo() -> i32 {
// CHECK: call void @bar
// CHECK: ret i32 0
std::intrinsics::r#try(|x| bar(x), 0 as *mut u8, 0 as *mut u8)
}