2020-11-08 18:00:00 -06:00
|
|
|
// Tests inlining of diverging calls.
|
|
|
|
//
|
2023-06-08 02:18:34 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2024-04-14 20:22:35 -05:00
|
|
|
//@ compile-flags: -Zinline-mir-hint-threshold=1000 -C debuginfo=full
|
2020-11-08 18:00:00 -06:00
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
// EMIT_MIR inline_diverging.f.Inline.diff
|
|
|
|
pub fn f() {
|
2023-10-20 20:03:13 -05:00
|
|
|
// CHECK-LABEL: fn f(
|
|
|
|
// CHECK: (inlined sleep)
|
2020-11-08 18:00:00 -06:00
|
|
|
sleep();
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR inline_diverging.g.Inline.diff
|
|
|
|
pub fn g(i: i32) -> u32 {
|
|
|
|
if i > 0 {
|
|
|
|
i as u32
|
|
|
|
} else {
|
2023-10-20 20:03:13 -05:00
|
|
|
// CHECK-LABEL: fn g(
|
|
|
|
// CHECK: (inlined panic)
|
2020-11-08 18:00:00 -06:00
|
|
|
panic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR inline_diverging.h.Inline.diff
|
|
|
|
pub fn h() {
|
2023-10-20 20:03:13 -05:00
|
|
|
// CHECK-LABEL: fn h(
|
|
|
|
// CHECK: (inlined call_twice::<!, fn() -> ! {sleep}>)
|
|
|
|
// CHECK-NOT: inlined
|
2020-11-08 18:00:00 -06:00
|
|
|
call_twice(sleep);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn call_twice<R, F: Fn() -> R>(f: F) -> (R, R) {
|
|
|
|
let a = f();
|
|
|
|
let b = f();
|
|
|
|
(a, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn panic() -> ! {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn sleep() -> ! {
|
|
|
|
loop {}
|
|
|
|
}
|