2024-04-20 06:19:34 -05:00
|
|
|
//@ test-mir-pass: GVN
|
2023-02-24 20:32:52 -06:00
|
|
|
//@ compile-flags: -O --crate-type=lib
|
2023-04-26 19:00:00 -05:00
|
|
|
//@ ignore-endian-big
|
|
|
|
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
2023-02-24 20:32:52 -06:00
|
|
|
|
|
|
|
use std::mem::transmute;
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.less_as_i8.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub fn less_as_i8() -> i8 {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn less_as_i8(
|
|
|
|
// CHECK: _0 = const -1_i8;
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute(std::cmp::Ordering::Less) }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.from_char.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub fn from_char() -> i32 {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn from_char(
|
|
|
|
// CHECK: _0 = const 82_i32;
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute('R') }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.valid_char.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub fn valid_char() -> char {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn valid_char(
|
|
|
|
// CHECK: _0 = const 'R';
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute(0x52_u32) }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.invalid_char.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn invalid_char() -> char {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn invalid_char(
|
|
|
|
// CHECK: _0 = const {transmute(0x7fffffff): char};
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute(i32::MAX) }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.invalid_bool.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn invalid_bool() -> bool {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn invalid_bool(
|
|
|
|
// CHECK: _0 = const {transmute(0xff): bool};
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute(-1_i8) }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.undef_union_as_integer.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn undef_union_as_integer() -> u32 {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn undef_union_as_integer(
|
|
|
|
// CHECK: _1 = Union32 {
|
|
|
|
// CHECK: _0 = move _1 as u32 (Transmute);
|
2024-06-02 19:18:33 -05:00
|
|
|
union Union32 {
|
|
|
|
value: u32,
|
|
|
|
unit: (),
|
|
|
|
}
|
2023-02-24 20:32:52 -06:00
|
|
|
unsafe { transmute(Union32 { unit: () }) }
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.unreachable_direct.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn unreachable_direct() -> ! {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn unreachable_direct(
|
2023-09-20 16:43:33 -05:00
|
|
|
// CHECK: = const ();
|
|
|
|
// CHECK: = const () as Never (Transmute);
|
2023-02-24 20:32:52 -06:00
|
|
|
let x: Never = unsafe { transmute(()) };
|
|
|
|
match x {}
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.unreachable_ref.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn unreachable_ref() -> ! {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn unreachable_ref(
|
|
|
|
// CHECK: = const {0x1 as &Never};
|
2023-02-24 20:32:52 -06:00
|
|
|
let x: &Never = unsafe { transmute(1_usize) };
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.unreachable_mut.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn unreachable_mut() -> ! {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn unreachable_mut(
|
|
|
|
// CHECK: = const {0x1 as &mut Never};
|
2023-02-24 20:32:52 -06:00
|
|
|
let x: &mut Never = unsafe { transmute(1_usize) };
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR transmute.unreachable_box.GVN.diff
|
2023-02-24 20:32:52 -06:00
|
|
|
pub unsafe fn unreachable_box() -> ! {
|
2023-10-16 15:32:18 -05:00
|
|
|
// CHECK-LABEL: fn unreachable_box(
|
|
|
|
// CHECK: = const Box::<Never>(
|
2023-02-24 20:32:52 -06:00
|
|
|
let x: Box<Never> = unsafe { transmute(1_usize) };
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Never {}
|