summaryrefslogtreecommitdiffstats
path: root/tests/codegen/issues/issue-115385-llvm-jump-threading.rs
blob: 142e3596d96176afb2557fb7ad0ed695d301ca4a (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
41
42
43
44
45
46
// compile-flags: -O -Ccodegen-units=1

#![crate_type = "lib"]

#[repr(i64)]
pub enum Boolean {
    False = 0,
    True = 1,
}

impl Clone for Boolean {
    fn clone(&self) -> Self {
        *self
    }
}

impl Copy for Boolean {}

extern "C" {
    fn set_value(foo: *mut i64);
    fn bar();
}

pub fn foo(x: bool) {
    let mut foo = core::mem::MaybeUninit::<i64>::uninit();
    unsafe {
        set_value(foo.as_mut_ptr());
    }

    if x {
        let l1 = unsafe { *foo.as_mut_ptr().cast::<Boolean>() };
        if matches!(l1, Boolean::False) {
            unsafe {
                *foo.as_mut_ptr() = 0;
            }
        }
    }

    let l2 = unsafe { *foo.as_mut_ptr() };
    if l2 == 2 {
        // CHECK: call void @bar
        unsafe {
            bar();
        }
    }
}