FileCheck casts.
This commit is contained in:
parent
68c409f8f6
commit
d8cffda66a
6 changed files with 53 additions and 50 deletions
|
@ -1,14 +0,0 @@
|
|||
// MIR for `redundant` after PreCodegen
|
||||
|
||||
fn redundant(_1: *const &u8) -> *const &u8 {
|
||||
debug x => _1;
|
||||
let mut _0: *const &u8;
|
||||
scope 1 (inlined generic_cast::<&u8, &u8>) {
|
||||
debug x => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
_0 = _1;
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// MIR for `roundtrip` after PreCodegen
|
||||
|
||||
fn roundtrip(_1: *const u8) -> *const u8 {
|
||||
debug x => _1;
|
||||
let mut _0: *const u8;
|
||||
let mut _2: *mut u8;
|
||||
|
||||
bb0: {
|
||||
StorageLive(_2);
|
||||
_2 = _1 as *mut u8 (PtrToPtr);
|
||||
_0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
|
||||
StorageDead(_2);
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// skip-filecheck
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// EMIT_MIR casts.redundant.InstSimplify.diff
|
||||
// EMIT_MIR casts.redundant.PreCodegen.after.mir
|
||||
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
|
||||
generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn generic_cast<T, U>(x: *const T) -> *const U {
|
||||
x as *const U
|
||||
}
|
||||
|
||||
// EMIT_MIR casts.roundtrip.PreCodegen.after.mir
|
||||
pub fn roundtrip(x: *const u8) -> *const u8 {
|
||||
x as *mut u8 as *const u8
|
||||
}
|
|
@ -7,15 +7,19 @@
|
|||
let mut _2: *const &u8;
|
||||
let mut _3: *const &u8;
|
||||
scope 1 (inlined generic_cast::<&u8, &u8>) {
|
||||
debug x => _1;
|
||||
debug x => _3;
|
||||
let mut _4: *const &u8;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
_3 = _1;
|
||||
- _2 = _3 as *const &u8 (PtrToPtr);
|
||||
+ _2 = _3;
|
||||
StorageLive(_4);
|
||||
_4 = _3;
|
||||
- _2 = move _4 as *const &u8 (PtrToPtr);
|
||||
+ _2 = move _4;
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
_0 = _2;
|
||||
StorageDead(_2);
|
21
tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff
Normal file
21
tests/mir-opt/instsimplify/casts.roundtrip.InstSimplify.diff
Normal file
|
@ -0,0 +1,21 @@
|
|||
- // MIR for `roundtrip` before InstSimplify
|
||||
+ // MIR for `roundtrip` after InstSimplify
|
||||
|
||||
fn roundtrip(_1: *const u8) -> *const u8 {
|
||||
debug x => _1;
|
||||
let mut _0: *const u8;
|
||||
let mut _2: *mut u8;
|
||||
let mut _3: *const u8;
|
||||
|
||||
bb0: {
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
_3 = _1;
|
||||
_2 = move _3 as *mut u8 (PtrToPtr);
|
||||
_0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
|
||||
StorageDead(_3);
|
||||
StorageDead(_2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
25
tests/mir-opt/instsimplify/casts.rs
Normal file
25
tests/mir-opt/instsimplify/casts.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
// unit-test: InstSimplify
|
||||
// compile-flags: -Zinline-mir
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[inline(always)]
|
||||
fn generic_cast<T, U>(x: *const T) -> *const U {
|
||||
x as *const U
|
||||
}
|
||||
|
||||
// EMIT_MIR casts.redundant.InstSimplify.diff
|
||||
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
|
||||
// CHECK-LABEL: fn redundant(
|
||||
// CHECK: inlined generic_cast
|
||||
// CHECK-NOT: as
|
||||
generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
|
||||
}
|
||||
|
||||
// EMIT_MIR casts.roundtrip.InstSimplify.diff
|
||||
pub fn roundtrip(x: *const u8) -> *const u8 {
|
||||
// CHECK-LABEL: fn roundtrip(
|
||||
// CHECK: _3 = _1;
|
||||
// CHECK: _2 = move _3 as *mut u8 (PtrToPtr);
|
||||
// CHECK: _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
|
||||
x as *mut u8 as *const u8
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue