Skip to content

Commit

Permalink
FileCheck transmute.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Oct 18, 2023
1 parent e665145 commit 3ae74ec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
23 changes: 22 additions & 1 deletion tests/mir-opt/const_prop/transmute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// unit-test: ConstProp
// compile-flags: -O --crate-type=lib
// ignore-endian-big
Expand All @@ -8,55 +7,77 @@ use std::mem::transmute;

// EMIT_MIR transmute.less_as_i8.ConstProp.diff
pub fn less_as_i8() -> i8 {
// CHECK-LABEL: fn less_as_i8(
// CHECK: _0 = const -1_i8;
unsafe { transmute(std::cmp::Ordering::Less) }
}

// EMIT_MIR transmute.from_char.ConstProp.diff
pub fn from_char() -> i32 {
// CHECK-LABEL: fn from_char(
// CHECK: _0 = const 82_i32;
unsafe { transmute('R') }
}

// EMIT_MIR transmute.valid_char.ConstProp.diff
pub fn valid_char() -> char {
// CHECK-LABEL: fn valid_char(
// CHECK: _0 = const 'R';
unsafe { transmute(0x52_u32) }
}

// EMIT_MIR transmute.invalid_char.ConstProp.diff
pub unsafe fn invalid_char() -> char {
// CHECK-LABEL: fn invalid_char(
// CHECK: _0 = const {transmute(0x7fffffff): char};
unsafe { transmute(i32::MAX) }
}

// EMIT_MIR transmute.invalid_bool.ConstProp.diff
pub unsafe fn invalid_bool() -> bool {
// CHECK-LABEL: fn invalid_bool(
// CHECK: _0 = const {transmute(0xff): bool};
unsafe { transmute(-1_i8) }
}

// EMIT_MIR transmute.undef_union_as_integer.ConstProp.diff
pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
unsafe { transmute(Union32 { unit: () }) }
}

// EMIT_MIR transmute.unreachable_direct.ConstProp.diff
pub unsafe fn unreachable_direct() -> ! {
// CHECK-LABEL: fn unreachable_direct(
// CHECK: [[unit:_.*]] = ();
// CHECK: move [[unit]] as Never (Transmute);
let x: Never = unsafe { transmute(()) };
match x {}
}

// EMIT_MIR transmute.unreachable_ref.ConstProp.diff
pub unsafe fn unreachable_ref() -> ! {
// CHECK-LABEL: fn unreachable_ref(
// CHECK: = const {0x1 as &Never};
let x: &Never = unsafe { transmute(1_usize) };
match *x {}
}

// EMIT_MIR transmute.unreachable_mut.ConstProp.diff
pub unsafe fn unreachable_mut() -> ! {
// CHECK-LABEL: fn unreachable_mut(
// CHECK: = const {0x1 as &mut Never};
let x: &mut Never = unsafe { transmute(1_usize) };
match *x {}
}

// EMIT_MIR transmute.unreachable_box.ConstProp.diff
pub unsafe fn unreachable_box() -> ! {
// CHECK-LABEL: fn unreachable_box(
// CHECK: = const Box::<Never>(
let x: Box<Never> = unsafe { transmute(1_usize) };
match *x {}
}
Expand Down
23 changes: 22 additions & 1 deletion tests/mir-opt/dataflow-const-prop/transmute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// unit-test: DataflowConstProp
// compile-flags: -O --crate-type=lib
// ignore-endian-big
Expand All @@ -8,55 +7,77 @@ use std::mem::transmute;

// EMIT_MIR transmute.less_as_i8.DataflowConstProp.diff
pub fn less_as_i8() -> i8 {
// CHECK-LABEL: fn less_as_i8(
// FIXME-CHECK: _0 = const -1_i8;
unsafe { transmute(std::cmp::Ordering::Less) }
}

// EMIT_MIR transmute.from_char.DataflowConstProp.diff
pub fn from_char() -> i32 {
// CHECK-LABEL: fn from_char(
// CHECK: _0 = const 82_i32;
unsafe { transmute('R') }
}

// EMIT_MIR transmute.valid_char.DataflowConstProp.diff
pub fn valid_char() -> char {
// CHECK-LABEL: fn valid_char(
// CHECK: _0 = const 'R';
unsafe { transmute(0x52_u32) }
}

// EMIT_MIR transmute.invalid_char.DataflowConstProp.diff
pub unsafe fn invalid_char() -> char {
// CHECK-LABEL: fn invalid_char(
// CHECK: _0 = const {transmute(0x7fffffff): char};
unsafe { transmute(i32::MAX) }
}

// EMIT_MIR transmute.invalid_bool.DataflowConstProp.diff
pub unsafe fn invalid_bool() -> bool {
// CHECK-LABEL: fn invalid_bool(
// CHECK: _0 = const {transmute(0xff): bool};
unsafe { transmute(-1_i8) }
}

// EMIT_MIR transmute.undef_union_as_integer.DataflowConstProp.diff
pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
unsafe { transmute(Union32 { unit: () }) }
}

// EMIT_MIR transmute.unreachable_direct.DataflowConstProp.diff
pub unsafe fn unreachable_direct() -> ! {
// CHECK-LABEL: fn unreachable_direct(
// CHECK: [[unit:_.*]] = ();
// CHECK: move [[unit]] as Never (Transmute);
let x: Never = unsafe { transmute(()) };
match x {}
}

// EMIT_MIR transmute.unreachable_ref.DataflowConstProp.diff
pub unsafe fn unreachable_ref() -> ! {
// CHECK-LABEL: fn unreachable_ref(
// CHECK: = const {0x1 as &Never};
let x: &Never = unsafe { transmute(1_usize) };
match *x {}
}

// EMIT_MIR transmute.unreachable_mut.DataflowConstProp.diff
pub unsafe fn unreachable_mut() -> ! {
// CHECK-LABEL: fn unreachable_mut(
// CHECK: = const {0x1 as &mut Never};
let x: &mut Never = unsafe { transmute(1_usize) };
match *x {}
}

// EMIT_MIR transmute.unreachable_box.DataflowConstProp.diff
pub unsafe fn unreachable_box() -> ! {
// CHECK-LABEL: fn unreachable_box(
// CHECK: = const Box::<Never>(
let x: Box<Never> = unsafe { transmute(1_usize) };
match *x {}
}
Expand Down

0 comments on commit 3ae74ec

Please sign in to comment.