File: call_arg_copy.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (46 lines) | stat: -rw-r--r-- 1,093 bytes parent folder | download
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
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: DeadStoreElimination-final
//@ compile-flags: -Zmir-enable-passes=+CopyProp

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

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

#[inline(never)]
fn use_both(_: i32, _: i32) {}

// EMIT_MIR call_arg_copy.move_simple.DeadStoreElimination-final.diff
fn move_simple(x: i32) {
    // CHECK-LABEL: fn move_simple(
    // CHECK: = use_both(_1, move _1)
    use_both(x, x);
}

#[repr(packed)]
struct Packed {
    x: u8,
    y: i32,
}

// EMIT_MIR call_arg_copy.move_packed.DeadStoreElimination-final.diff
#[custom_mir(dialect = "analysis")]
fn move_packed(packed: Packed) {
    // CHECK-LABEL: fn move_packed(
    // CHECK: = use_both(const 0_i32, (_1.1: i32))
    mir!(
        {
            // We have a packed struct, verify that the copy is not turned into a move.
            Call(RET = use_both(0, packed.y), ReturnTo(ret), UnwindContinue())
        }
        ret = {
            Return()
        }
    )
}

fn main() {
    move_simple(1);
    move_packed(Packed { x: 0, y: 1 });
}