2024-07-27 01:36:17 -05:00
|
|
|
//@ test-mir-pass: InstSimplify-after-simplifycfg
|
2024-02-22 06:10:29 -06:00
|
|
|
//@ compile-flags: -Zinline-mir
|
2023-10-16 14:58:20 -05:00
|
|
|
#![crate_type = "lib"]
|
2024-04-14 13:12:32 -05:00
|
|
|
#![feature(core_intrinsics)]
|
2023-10-16 14:58:20 -05:00
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn generic_cast<T, U>(x: *const T) -> *const U {
|
|
|
|
x as *const U
|
|
|
|
}
|
|
|
|
|
2024-07-27 01:36:17 -05:00
|
|
|
// EMIT_MIR casts.redundant.InstSimplify-after-simplifycfg.diff
|
2023-10-16 14:58:20 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-07-27 01:36:17 -05:00
|
|
|
// EMIT_MIR casts.roundtrip.InstSimplify-after-simplifycfg.diff
|
2023-10-16 14:58:20 -05:00
|
|
|
pub fn roundtrip(x: *const u8) -> *const u8 {
|
|
|
|
// CHECK-LABEL: fn roundtrip(
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: _4 = copy _1;
|
2023-07-02 10:50:24 -05:00
|
|
|
// CHECK: _3 = move _4 as *mut u8 (PtrToPtr);
|
2024-06-12 03:22:31 -05:00
|
|
|
// CHECK: _2 = move _3 as *const u8 (PtrToPtr);
|
2023-10-16 14:58:20 -05:00
|
|
|
x as *mut u8 as *const u8
|
|
|
|
}
|
2024-04-14 13:12:32 -05:00
|
|
|
|
2024-07-27 01:36:17 -05:00
|
|
|
// EMIT_MIR casts.roundtrip.InstSimplify-after-simplifycfg.diff
|
2024-04-14 13:12:32 -05:00
|
|
|
pub fn cast_thin_via_aggregate(x: *const u8) -> *const () {
|
|
|
|
// CHECK-LABEL: fn cast_thin_via_aggregate(
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK: _2 = copy _1;
|
2024-04-14 13:12:32 -05:00
|
|
|
// CHECK: _0 = move _2 as *const () (PtrToPtr);
|
|
|
|
std::intrinsics::aggregate_raw_ptr(x, ())
|
|
|
|
}
|