rust/tests/mir-opt/building/custom/unwind_terminate.rs
Tomasz Miąsko 78da577650 Custom MIR: Support cleanup blocks
Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the
unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:23:58 +01:00

35 lines
714 B
Rust

// compile-flags: --crate-type=lib
// edition:2021
#![feature(custom_mir, core_intrinsics)]
use core::intrinsics::mir::*;
// CHECK-LABEL: fn f()
// CHECK: bb1 (cleanup): {
// CHECK-NEXT: terminate(abi);
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn f() {
mir!(
{
Return()
}
bb1(cleanup) = {
UnwindTerminate(ReasonAbi)
}
)
}
// CHECK-LABEL: fn g()
// CHECK: bb1 (cleanup): {
// CHECK-NEXT: terminate(cleanup);
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn g() {
mir!(
{
Return()
}
bb1(cleanup) = {
UnwindTerminate(ReasonInCleanup)
}
)
}