From 1dffca305304ed3b7b42e2a3b34eec7c5b0af5dd Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 4 Aug 2024 13:00:59 -0400 Subject: [PATCH] Add transmute intrinsics test --- src/compile_test.rs | 1 + test/intrinsics/transmute.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/intrinsics/transmute.rs diff --git a/src/compile_test.rs b/src/compile_test.rs index 03a2bce4..d2f5ad51 100644 --- a/src/compile_test.rs +++ b/src/compile_test.rs @@ -754,6 +754,7 @@ run_test! {intrinsics,copy_nonoverlaping,stable} run_test! {intrinsics,ptr_offset_from_unsigned,stable} run_test! {intrinsics,arith_offset,stable} run_test! {intrinsics,cmp_bytes,stable} +run_test! {intrinsics,transmute,stable} run_test! {alloc,abox,stable} run_test! {alloc,raw_vec,stable} diff --git a/test/intrinsics/transmute.rs b/test/intrinsics/transmute.rs new file mode 100644 index 00000000..f2dc398b --- /dev/null +++ b/test/intrinsics/transmute.rs @@ -0,0 +1,36 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params +)] +#![allow(internal_features, incomplete_features, unused_variables, dead_code)] +#![no_std] +include!("../common.rs"); +extern crate core; + +use core::intrinsics::transmute; + +fn main() { + let slice = unsafe { transmute::<&str, &[u8]>(".NET") }; + test_eq!(black_box(slice), &[46, 78, 69, 84]); + + fn forty_two() -> i32 { + 42 + } + let pointer = forty_two as *const (); + let function = unsafe { + transmute::<*const (), fn() -> i32>(pointer) + }; + test_eq!(function(), black_box(42)); + + + let ptr_i32: &mut i32 = &mut 3; + let transmuted_to_u32: &mut u32 = unsafe { + transmute::<&mut i32, &mut u32>(ptr_i32) + }; + let ptr_u32: &mut u32 = &mut 3; + test_eq!(transmuted_to_u32, black_box(ptr_u32)); +}