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:
parent
1920f817ca
commit
919c5fe6b9
2 changed files with 36 additions and 0 deletions
19
src/test/codegen/catch-unwind.rs
Normal file
19
src/test/codegen/catch-unwind.rs
Normal 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()
|
||||
}
|
||||
17
src/test/codegen/try-panic-abort.rs
Normal file
17
src/test/codegen/try-panic-abort.rs
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue