Add test.

This commit is contained in:
Camille GILLOT 2025-06-16 14:07:25 +00:00
parent 75e7cf5f85
commit 71afc6f463
2 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,31 @@
- // MIR for `main` before CopyProp
+ // MIR for `main` after CopyProp
fn main() -> () {
let mut _0: ();
let mut _1: *const char;
let mut _2: char;
let mut _3: char;
let mut _4: char;
let mut _5: char;
let mut _6: &char;
let mut _7: ();
bb0: {
_1 = &raw const _2;
_3 = const 'b';
_5 = copy _3;
_6 = &_3;
- _4 = copy _5;
+ _3 = copy _5;
(*_1) = copy (*_6);
_6 = &_5;
- _7 = dump_var::<char>(copy _4) -> [return: bb1, unwind unreachable];
+ _7 = dump_var::<char>(copy _3) -> [return: bb1, unwind unreachable];
}
bb1: {
return;
}
}

View file

@ -0,0 +1,45 @@
//@ 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;
// CHECK-NEXT: _3 = copy _5
_4 = _5;
// CHECK-NEXT: (*_1) = copy (*_6);
*_1 = *_6;
// CHECK-NEXT: _6 = &_5;
_6 = &_5;
// CHECK-NEXT: _7 = dump_var::<char>(copy _3)
Call(_7 = dump_var(_4), ReturnTo(bb1), UnwindUnreachable())
}
bb1 = { Return() }
}
}
fn dump_var<T>(_: T) {}
// EMIT_MIR write_to_borrowed.main.CopyProp.diff