From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- tests/codegen/intrinsics/transmute.rs | 75 +++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) (limited to 'tests/codegen/intrinsics') diff --git a/tests/codegen/intrinsics/transmute.rs b/tests/codegen/intrinsics/transmute.rs index 664e697c2..fe4249400 100644 --- a/tests/codegen/intrinsics/transmute.rs +++ b/tests/codegen/intrinsics/transmute.rs @@ -14,10 +14,10 @@ use std::intrinsics::{transmute, transmute_unchecked}; // Some of these need custom MIR to not get removed by MIR optimizations. use std::intrinsics::mir::*; -enum Never {} +pub enum ZstNever {} #[repr(align(2))] -pub struct BigNever(Never, u16, Never); +pub struct BigNever(ZstNever, u16, ZstNever); #[repr(align(8))] pub struct Scalar64(i64); @@ -56,11 +56,13 @@ pub unsafe fn check_bigger_array(x: [u32; 3]) -> [u32; 7] { transmute_unchecked(x) } -// CHECK-LABEL: @check_to_uninhabited( +// CHECK-LABEL: @check_to_empty_array( #[no_mangle] #[custom_mir(dialect = "runtime", phase = "optimized")] -pub unsafe fn check_to_uninhabited(x: u16) -> BigNever { +pub unsafe fn check_to_empty_array(x: [u32; 5]) -> [u32; 0] { + // CHECK-NOT: trap // CHECK: call void @llvm.trap + // CHECK-NOT: trap mir!{ { RET = CastTransmute(x); @@ -69,6 +71,37 @@ pub unsafe fn check_to_uninhabited(x: u16) -> BigNever { } } +// CHECK-LABEL: @check_from_empty_array( +#[no_mangle] +#[custom_mir(dialect = "runtime", phase = "optimized")] +pub unsafe fn check_from_empty_array(x: [u32; 0]) -> [u32; 5] { + // CHECK-NOT: trap + // CHECK: call void @llvm.trap + // CHECK-NOT: trap + mir!{ + { + RET = CastTransmute(x); + Return() + } + } +} + +// CHECK-LABEL: @check_to_uninhabited( +#[no_mangle] +#[custom_mir(dialect = "runtime", phase = "optimized")] +pub unsafe fn check_to_uninhabited(x: u16) { + // CHECK-NOT: trap + // CHECK: call void @llvm.trap + // CHECK-NOT: trap + mir!{ + let temp: BigNever; + { + temp = CastTransmute(x); + Return() + } + } +} + // CHECK-LABEL: @check_from_uninhabited( #[no_mangle] #[custom_mir(dialect = "runtime", phase = "optimized")] @@ -366,6 +399,40 @@ pub unsafe fn check_issue_109992(x: ()) -> [(); 1] { } } +// CHECK-LABEL: @check_unit_to_never( +#[no_mangle] +#[custom_mir(dialect = "runtime", phase = "optimized")] +pub unsafe fn check_unit_to_never(x: ()) { + // This uses custom MIR to avoid MIR optimizations having removed ZST ops. + + // CHECK-NOT: trap + // CHECK: call void @llvm.trap + // CHECK-NOT: trap + mir!{ + let temp: ZstNever; + { + temp = CastTransmute(x); + Return() + } + } +} + +// CHECK-LABEL: @check_unit_from_never( +#[no_mangle] +#[custom_mir(dialect = "runtime", phase = "optimized")] +pub unsafe fn check_unit_from_never(x: ZstNever) -> () { + // This uses custom MIR to avoid MIR optimizations having removed ZST ops. + + // CHECK: start + // CHECK-NEXT: ret void + mir!{ + { + RET = CastTransmute(x); + Return() + } + } +} + // CHECK-LABEL: @check_maybe_uninit_pair(i16 %x.0, i64 %x.1) #[no_mangle] pub unsafe fn check_maybe_uninit_pair( -- cgit v1.2.3