about summary refs log tree commit diff
path: root/tests/mir-opt/pre-codegen/clone_as_copy.rs
blob: 00f24754d59131d2195cb918e46f587fb6d32d84 (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
//@ compile-flags: -Cdebuginfo=full

// Check if we have transformed the nested clone to the copy in the complete pipeline.

#[derive(Clone)]
struct AllCopy {
    a: i32,
    b: u64,
    c: [i8; 3],
}

#[derive(Clone)]
struct NestCopy {
    a: i32,
    b: AllCopy,
    c: [i8; 3],
}

#[derive(Clone)]
enum Enum1 {
    A(AllCopy),
    B(NestCopy),
}

// EMIT_MIR clone_as_copy.clone_as_copy.PreCodegen.after.mir
fn clone_as_copy(v: &NestCopy) -> NestCopy {
    // CHECK-LABEL: fn clone_as_copy(
    // CHECK: let [[DEAD_VAR:_.*]]: &AllCopy;
    // CHECK: bb0: {
    // CHECK-NEXT: DBG: [[DEAD_VAR]] = &((*_1).1: AllCopy)
    // CHECK-NEXT: _0 = copy (*_1);
    // CHECK-NEXT: return;
    v.clone()
}

// EMIT_MIR clone_as_copy.enum_clone_as_copy.PreCodegen.after.mir
fn enum_clone_as_copy(v: &Enum1) -> Enum1 {
    // CHECK-LABEL: fn enum_clone_as_copy(
    // CHECK: bb0: {
    // CHECK-NEXT: _0 = copy (*_1);
    // CHECK-NEXT: return;
    v.clone()
}