2022-08-20 23:47:53 -05:00
|
|
|
// unit-test: LowerIntrinsics
|
2023-06-08 02:18:34 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2022-08-20 23:47:53 -05:00
|
|
|
|
2023-04-12 07:57:27 -05:00
|
|
|
#![feature(core_intrinsics, intrinsics, rustc_attrs)]
|
2020-11-13 18:00:00 -06:00
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.wrapping.LowerIntrinsics.diff
|
2022-03-24 21:30:23 -05:00
|
|
|
pub fn wrapping(a: i32, b: i32) {
|
2020-11-13 18:00:00 -06:00
|
|
|
let _x = core::intrinsics::wrapping_add(a, b);
|
|
|
|
let _y = core::intrinsics::wrapping_sub(a, b);
|
|
|
|
let _z = core::intrinsics::wrapping_mul(a, b);
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:58:20 -05:00
|
|
|
// EMIT_MIR lower_intrinsics.unchecked.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn unchecked(a: i32, b: i32) {
|
2023-06-03 02:41:50 -05:00
|
|
|
let _a = core::intrinsics::unchecked_add(a, b);
|
|
|
|
let _b = core::intrinsics::unchecked_sub(a, b);
|
|
|
|
let _c = core::intrinsics::unchecked_mul(a, b);
|
2023-06-01 01:58:20 -05:00
|
|
|
let _x = core::intrinsics::unchecked_div(a, b);
|
|
|
|
let _y = core::intrinsics::unchecked_rem(a, b);
|
2023-06-03 02:41:50 -05:00
|
|
|
let _i = core::intrinsics::unchecked_shl(a, b);
|
|
|
|
let _j = core::intrinsics::unchecked_shr(a, b);
|
2023-06-01 01:58:20 -05:00
|
|
|
}
|
|
|
|
|
2020-11-13 18:00:00 -06:00
|
|
|
// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
|
|
|
|
pub fn size_of<T>() -> usize {
|
|
|
|
core::intrinsics::size_of::<T>()
|
|
|
|
}
|
|
|
|
|
2021-09-10 18:54:10 -05:00
|
|
|
// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff
|
|
|
|
pub fn align_of<T>() -> usize {
|
|
|
|
core::intrinsics::min_align_of::<T>()
|
|
|
|
}
|
|
|
|
|
2020-11-13 18:00:00 -06:00
|
|
|
// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
|
|
|
|
pub fn forget<T>(t: T) {
|
2020-12-28 18:00:00 -06:00
|
|
|
core::intrinsics::forget(t)
|
2020-11-13 18:00:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.unreachable.LowerIntrinsics.diff
|
|
|
|
pub fn unreachable() -> ! {
|
|
|
|
unsafe { core::intrinsics::unreachable() };
|
|
|
|
}
|
|
|
|
|
2020-11-15 18:00:00 -06:00
|
|
|
// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
|
|
|
|
pub fn non_const<T>() -> usize {
|
|
|
|
// Check that lowering works with non-const operand as a func.
|
|
|
|
let size_of_t = core::intrinsics::size_of::<T>;
|
|
|
|
size_of_t()
|
|
|
|
}
|
2020-12-10 18:00:00 -06:00
|
|
|
|
2023-02-24 20:32:52 -06:00
|
|
|
// EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff
|
|
|
|
pub fn transmute_inhabited(c: std::cmp::Ordering) -> i8 {
|
|
|
|
unsafe { std::mem::transmute(c) }
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.transmute_uninhabited.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn transmute_uninhabited(u: ()) -> Never {
|
|
|
|
unsafe { std::mem::transmute::<(), Never>(u) }
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.transmute_ref_dst.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn transmute_ref_dst<T: ?Sized>(u: &T) -> *const T {
|
|
|
|
unsafe { std::mem::transmute(u) }
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn transmute_to_ref_uninhabited() -> ! {
|
|
|
|
let x: &Never = std::mem::transmute(1usize);
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn transmute_to_mut_uninhabited() -> ! {
|
|
|
|
let x: &mut Never = std::mem::transmute(1usize);
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn transmute_to_box_uninhabited() -> ! {
|
|
|
|
let x: Box<Never> = std::mem::transmute(1usize);
|
|
|
|
match *x {}
|
|
|
|
}
|
|
|
|
|
2020-12-10 18:00:00 -06:00
|
|
|
pub enum E {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.discriminant.LowerIntrinsics.diff
|
|
|
|
pub fn discriminant<T>(t: T) {
|
|
|
|
core::intrinsics::discriminant_value(&t);
|
|
|
|
core::intrinsics::discriminant_value(&0);
|
|
|
|
core::intrinsics::discriminant_value(&());
|
|
|
|
core::intrinsics::discriminant_value(&E::B);
|
|
|
|
}
|
2022-06-30 03:16:05 -05:00
|
|
|
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
// Cannot use `std::intrinsics::copy_nonoverlapping` as that is a wrapper function
|
2023-04-12 07:57:27 -05:00
|
|
|
#[rustc_nounwind]
|
2022-06-30 03:16:05 -05:00
|
|
|
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
|
|
|
|
pub fn f_copy_nonoverlapping() {
|
|
|
|
let src = ();
|
|
|
|
let mut dst = ();
|
|
|
|
unsafe {
|
|
|
|
copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.assume.LowerIntrinsics.diff
|
|
|
|
pub fn assume() {
|
|
|
|
unsafe {
|
|
|
|
std::intrinsics::assume(true);
|
|
|
|
}
|
|
|
|
}
|
2023-02-18 15:45:10 -06:00
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.with_overflow.LowerIntrinsics.diff
|
|
|
|
pub fn with_overflow(a: i32, b: i32) {
|
|
|
|
let _x = core::intrinsics::add_with_overflow(a, b);
|
|
|
|
let _y = core::intrinsics::sub_with_overflow(a, b);
|
|
|
|
let _z = core::intrinsics::mul_with_overflow(a, b);
|
|
|
|
}
|
2023-03-11 17:32:54 -06:00
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff
|
|
|
|
pub fn read_via_copy_primitive(r: &i32) -> i32 {
|
|
|
|
unsafe { core::intrinsics::read_via_copy(r) }
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff
|
|
|
|
pub fn read_via_copy_uninhabited(r: &Never) -> Never {
|
|
|
|
unsafe { core::intrinsics::read_via_copy(r) }
|
|
|
|
}
|
|
|
|
|
2023-04-30 01:32:40 -05:00
|
|
|
// EMIT_MIR lower_intrinsics.write_via_move_string.LowerIntrinsics.diff
|
|
|
|
pub fn write_via_move_string(r: &mut String, v: String) {
|
|
|
|
unsafe { core::intrinsics::write_via_move(r, v) }
|
|
|
|
}
|
|
|
|
|
2023-03-11 17:32:54 -06:00
|
|
|
pub enum Never {}
|
2023-03-15 10:29:52 -05:00
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.option_payload.LowerIntrinsics.diff
|
|
|
|
pub fn option_payload(o: &Option<usize>, p: &Option<String>) {
|
|
|
|
unsafe {
|
|
|
|
let _x = core::intrinsics::option_payload_ptr(o);
|
|
|
|
let _y = core::intrinsics::option_payload_ptr(p);
|
|
|
|
}
|
|
|
|
}
|
2023-04-25 14:10:55 -05:00
|
|
|
|
|
|
|
// EMIT_MIR lower_intrinsics.ptr_offset.LowerIntrinsics.diff
|
|
|
|
pub unsafe fn ptr_offset(p: *const i32, d: isize) -> *const i32 {
|
|
|
|
core::intrinsics::offset(p, d)
|
|
|
|
}
|