summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/simplify_locals.rs
blob: d4052e521dead0368f108d31aa33cd39208bc927 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// skip-filecheck
// unit-test: SimplifyLocals-before-const-prop


#![feature(thread_local)]

#[derive(Copy, Clone)]
enum E {
     A,
     B,
}

// EMIT_MIR simplify_locals.c.SimplifyLocals-before-const-prop.diff
fn c() {
    let bytes = [0u8; 10];
    // Unused cast
    let _: &[u8] = &bytes;
}

// EMIT_MIR simplify_locals.d1.SimplifyLocals-before-const-prop.diff
fn d1() {
    // Unused set discriminant
    let _ = E::A;
}

// EMIT_MIR simplify_locals.d2.SimplifyLocals-before-const-prop.diff
fn d2() {
    // Unused set discriminant
    {(10, E::A)}.1 = E::B;
}

// EMIT_MIR simplify_locals.r.SimplifyLocals-before-const-prop.diff
fn r() {
    let mut a = 1;
    // Unused references
    let _ = &a;
    let _ = &mut a;
}

#[thread_local] static mut X: u32 = 0;

// EMIT_MIR simplify_locals.t1.SimplifyLocals-before-const-prop.diff
fn t1() {
    // Unused thread local
    unsafe { X };
}

// EMIT_MIR simplify_locals.t2.SimplifyLocals-before-const-prop.diff
fn t2() {
    // Unused thread local
    unsafe { &mut X };
}

// EMIT_MIR simplify_locals.t3.SimplifyLocals-before-const-prop.diff
fn t3() {
    // Unused thread local
    unsafe { *&mut X };
}

// EMIT_MIR simplify_locals.t4.SimplifyLocals-before-const-prop.diff
fn t4() -> u32 {
    // Used thread local
    unsafe { X + 1 }
}

// EMIT_MIR simplify_locals.expose_addr.SimplifyLocals-before-const-prop.diff
fn expose_addr(p: *const usize) {
    // Used pointer to address cast. Has a side effect of exposing the provenance.
    p as usize;
}

fn main() {
    c();
    d1();
    d2();
    r();
    t1();
    t2();
    t3();
    t4();
    expose_addr(&0);
}