about summary refs log tree commit diff
path: root/tests/mir-opt/dataflow-const-prop/aggregate_copy.rs
blob: 9cd485813bc9967e8d30ae52f8166c087a3526a4 (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
//! Verify that we manage to propagate the value of aggregate `a` even without directly mentioning
//! the contained scalars.
//@ test-mir-pass: DataflowConstProp
//@ compile-flags: -Zdump-mir-exclude-alloc-bytes

const Foo: (u32, u32) = (5, 3);

fn foo() -> u32 {
    // CHECK-LABEL: fn foo(
    // CHECK: debug a => [[a:_.*]];
    // CHECK: debug b => [[b:_.*]];
    // CHECK: debug c => [[c:_.*]];

    // CHECK:bb0: {
    // CHECK:    [[a]] = const Foo;
    // CHECK:    [[b]] = const (5_u32, 3_u32);
    // CHECK:    [[c]] = const 3_u32;
    // CHECK:    {{_.*}} = const 3_u32;
    // CHECK:    {{_.*}} = const true;
    // CHECK:    switchInt(const true) -> [0: bb2, otherwise: bb1];

    // CHECK:bb1: {
    // CHECK:    _0 = const 5_u32;
    // CHECK:    goto -> bb3;

    // CHECK:bb2: {
    // CHECK:    _0 = const 13_u32;
    // CHECK:    goto -> bb3;

    let a = Foo;
    // This copies the struct in `a`. We want to ensure that we do track the contents of `a`
    // because we need to read `b` later.
    let b = a;
    let c = b.1;
    if c >= 2 { b.0 } else { 13 }
}

fn main() {
    // CHECK-LABEL: fn main(
    foo();
}

// EMIT_MIR aggregate_copy.foo.DataflowConstProp.diff