about summary refs log tree commit diff
path: root/tests/mir-opt/copy-prop/write_to_borrowed.rs
blob: 06e617b8bfb5333d27521dd80d35fea8732c5022 (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
//@ test-mir-pass: CopyProp

#![feature(custom_mir, core_intrinsics)]
#![allow(internal_features)]

use std::intrinsics::mir::*;

#[custom_mir(dialect = "runtime")]
fn main() {
    mir! {
        // Both _3 and _5 are borrowed, check that we do not unify them, and that we do not
        // introduce a write to any of them.
        let _1;
        let _2;
        let _3;
        let _4;
        let _5;
        let _6;
        let _7;
        // CHECK: bb0: {
        {
            // CHECK-NEXT: _1 = &raw const _2;
            _1 = core::ptr::addr_of!(_2);
            // CHECK-NEXT: _3 = const 'b';
            _3 = 'b';
            // CHECK-NEXT: _5 = copy _3;
            _5 = _3;
            // CHECK-NEXT: _6 = &_3;
            _6 = &_3;
            _4 = _5;
            // CHECK-NEXT: (*_1) = copy (*_6);
            *_1 = *_6;
            // CHECK-NEXT: _6 = &_5;
            _6 = &_5;
            // CHECK-NEXT: _7 = dump_var::<char>(copy _5)
            Call(_7 = dump_var(_4), ReturnTo(bb1), UnwindUnreachable())
        }
        bb1 = { Return() }
    }
}

fn dump_var<T>(_: T) {}

// EMIT_MIR write_to_borrowed.main.CopyProp.diff