2023-07-16 08:11:10 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2024-01-06 12:34:25 -06:00
|
|
|
// unit-test: DeadStoreElimination-final
|
2023-07-16 08:11:10 -05:00
|
|
|
// compile-flags: -Zmir-enable-passes=+CopyProp
|
|
|
|
|
2023-08-23 11:00:42 -05:00
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
#![feature(custom_mir)]
|
|
|
|
#![allow(internal_features)]
|
|
|
|
|
|
|
|
use std::intrinsics::mir::*;
|
|
|
|
|
2023-07-16 08:11:10 -05:00
|
|
|
#[inline(never)]
|
|
|
|
fn use_both(_: i32, _: i32) {}
|
|
|
|
|
2024-01-06 12:34:25 -06:00
|
|
|
// EMIT_MIR call_arg_copy.move_simple.DeadStoreElimination-final.diff
|
2023-07-16 08:11:10 -05:00
|
|
|
fn move_simple(x: i32) {
|
2024-01-06 12:34:25 -06:00
|
|
|
// CHECK-LABEL: fn move_simple(
|
|
|
|
// CHECK: = use_both(_1, move _1)
|
2023-07-16 08:11:10 -05:00
|
|
|
use_both(x, x);
|
|
|
|
}
|
|
|
|
|
2023-08-23 11:00:42 -05:00
|
|
|
#[repr(packed)]
|
|
|
|
struct Packed {
|
|
|
|
x: u8,
|
|
|
|
y: i32,
|
|
|
|
}
|
|
|
|
|
2024-01-06 12:34:25 -06:00
|
|
|
// EMIT_MIR call_arg_copy.move_packed.DeadStoreElimination-final.diff
|
2023-08-23 11:00:42 -05:00
|
|
|
#[custom_mir(dialect = "analysis")]
|
|
|
|
fn move_packed(packed: Packed) {
|
2024-01-06 12:34:25 -06:00
|
|
|
// CHECK-LABEL: fn move_packed(
|
|
|
|
// CHECK: = use_both(const 0_i32, (_1.1: i32))
|
2023-08-23 11:00:42 -05:00
|
|
|
mir!(
|
|
|
|
{
|
2024-01-06 12:34:25 -06:00
|
|
|
// We have a packed struct, verify that the copy is not turned into a move.
|
2023-12-26 12:31:52 -06:00
|
|
|
Call(RET = use_both(0, packed.y), ReturnTo(ret), UnwindContinue())
|
2023-08-23 11:00:42 -05:00
|
|
|
}
|
|
|
|
ret = {
|
|
|
|
Return()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-07-16 08:11:10 -05:00
|
|
|
fn main() {
|
|
|
|
move_simple(1);
|
2023-08-23 11:00:42 -05:00
|
|
|
move_packed(Packed { x: 0, y: 1 });
|
2023-07-16 08:11:10 -05:00
|
|
|
}
|