summaryrefslogtreecommitdiffstats
path: root/tests/codegen/intrinsics
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/codegen/intrinsics
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/intrinsics')
-rw-r--r--tests/codegen/intrinsics/transmute.rs75
1 files changed, 71 insertions, 4 deletions
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(