summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/inline/inline_diverging.rs
blob: ae6f814c290c8ee060a81ae45844c79324e57056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Tests inlining of diverging calls.
//
// ignore-wasm32-bare compiled with panic=abort by default
#![crate_type = "lib"]

// EMIT_MIR inline_diverging.f.Inline.diff
pub fn f() {
    sleep();
}

// EMIT_MIR inline_diverging.g.Inline.diff
pub fn g(i: i32) -> u32 {
    if i > 0 {
        i as u32
    } else {
        panic();
    }
}

// EMIT_MIR inline_diverging.h.Inline.diff
pub fn h() {
    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 {}
}