From c8b310e05b3e355004c58ae49f0e8bb1d947cd4a Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 9 Aug 2024 16:22:58 -0400 Subject: [PATCH 1/3] add is_val_statically_known test --- src/compile_test.rs | 1 + src/lib.rs | 5 ++-- test/intrinsics/is_val_statically_known.rs | 35 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/intrinsics/is_val_statically_known.rs diff --git a/src/compile_test.rs b/src/compile_test.rs index 28100085..a01f95ea 100644 --- a/src/compile_test.rs +++ b/src/compile_test.rs @@ -705,6 +705,7 @@ run_test! {intrinsics,catch,stable} run_test! {intrinsics,cmp_bytes,stable} run_test! {intrinsics,copy_nonoverlaping,stable} run_test! {intrinsics,ctpop,stable} +run_test! {intrinsics,is_val_statically_known,stable} run_test! {intrinsics,malloc,stable} run_test! {intrinsics,offset_of,unstable} run_test! {intrinsics,overflow_ops,stable} diff --git a/src/lib.rs b/src/lib.rs index 947873a5..b74f3653 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -320,9 +320,10 @@ impl ArchiveBuilderBuilder for RlibArchiveBuilder { &self, _sess: &Session, _lib_name: &str, - _dll_imports: std::vec::Vec<(std::string::String, std::option::Option)>, + _dll_imports: &[rustc_session::cstore::DllImport], _tmpdir: &Path, - ) { + _bool: bool, + ) -> PathBuf { unimplemented!("creating dll imports is not supported"); } } diff --git a/test/intrinsics/is_val_statically_known.rs b/test/intrinsics/is_val_statically_known.rs new file mode 100644 index 00000000..24aec1d2 --- /dev/null +++ b/test/intrinsics/is_val_statically_known.rs @@ -0,0 +1,35 @@ +#![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::is_val_statically_known; + +fn main() { + test_eq!(is_val_statically_known(42), true); + test_eq!(is_val_statically_known([42]), false); + test_eq!(is_val_statically_known("42"), false); + test_eq!(is_val_statically_known(FortyTwo {}), false); + test_eq!(is_val_statically_known(FortyTwo {}.forty_two()), false); +} + +#[derive(Copy, Clone)] +struct FortyTwo {} + +trait Return { + fn forty_two(&self) -> usize; +} + +impl Return for FortyTwo { + fn forty_two(&self) -> usize { + 42 + } +} From 247aa5e90c8daa33a60763c4a249649e36d64a3c Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 9 Aug 2024 16:36:17 -0400 Subject: [PATCH 2/3] add ptr_mask test --- src/compile_test.rs | 1 + test/intrinsics/is_val_statically_known.rs | 13 +++++--- test/intrinsics/ptr_mask.rs | 38 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 test/intrinsics/ptr_mask.rs diff --git a/src/compile_test.rs b/src/compile_test.rs index a01f95ea..6f26daee 100644 --- a/src/compile_test.rs +++ b/src/compile_test.rs @@ -711,6 +711,7 @@ run_test! {intrinsics,offset_of,unstable} run_test! {intrinsics,overflow_ops,stable} run_test! {intrinsics,pow_sqrt,stable} run_test! {intrinsics,printf,stable} +run_test! {intrinsics,ptr_mask,stable} run_test! {intrinsics,ptr_offset_from_unsigned,stable} run_test! {intrinsics,round,stable} run_test! {intrinsics,size_of_val,stable} diff --git a/test/intrinsics/is_val_statically_known.rs b/test/intrinsics/is_val_statically_known.rs index 24aec1d2..74127d21 100644 --- a/test/intrinsics/is_val_statically_known.rs +++ b/test/intrinsics/is_val_statically_known.rs @@ -14,11 +14,14 @@ extern crate core; use core::intrinsics::is_val_statically_known; fn main() { - test_eq!(is_val_statically_known(42), true); - test_eq!(is_val_statically_known([42]), false); - test_eq!(is_val_statically_known("42"), false); - test_eq!(is_val_statically_known(FortyTwo {}), false); - test_eq!(is_val_statically_known(FortyTwo {}.forty_two()), false); + test_eq!(is_val_statically_known(42), black_box(true)); + test_eq!(is_val_statically_known([42]), black_box(false)); + test_eq!(is_val_statically_known("42"), black_box(false)); + test_eq!(is_val_statically_known(FortyTwo {}), black_box(false)); + test_eq!( + is_val_statically_known(FortyTwo {}.forty_two()), + black_box(false) + ); } #[derive(Copy, Clone)] diff --git a/test/intrinsics/ptr_mask.rs b/test/intrinsics/ptr_mask.rs new file mode 100644 index 00000000..ec43d4ee --- /dev/null +++ b/test/intrinsics/ptr_mask.rs @@ -0,0 +1,38 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params, + ptr_mask, + strict_provenance +)] +#![allow(internal_features, incomplete_features, unused_variables, dead_code)] +#![no_std] +include!("../common.rs"); +extern crate core; + +use core::intrinsics::ptr_mask; + +fn main() { + let v = 17_u32; + let ptr: *const u32 = &v; + + // `u32` is 4 bytes aligned, + // which means that lower 2 bits are always 0. + let tag_mask = 0b11; + let mask = !tag_mask; + + // We can store something in these lower bits + let tagged_ptr = ptr.map_addr(|a| a | 0b10); + + // Get the "tag" back + let tag = tagged_ptr.addr() & tag_mask; + assert_eq!(tag, black_box(0b10)); + + // Note that `tagged_ptr` is unaligned, it's UB to read from it. + // To get original pointer `mask` can be used: + let masked_ptr = ptr_mask(tagged_ptr, mask); + assert_eq!(unsafe { *masked_ptr }, black_box(17)); +} From 9e53e3205c19c2be7fe826b14a44a81293a16612 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 9 Aug 2024 16:42:24 -0400 Subject: [PATCH 3/3] add type_name test --- src/compile_test.rs | 1 + src/lib.rs | 5 ++--- test/intrinsics/type_name.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 test/intrinsics/type_name.rs diff --git a/src/compile_test.rs b/src/compile_test.rs index 6f26daee..1d425433 100644 --- a/src/compile_test.rs +++ b/src/compile_test.rs @@ -718,6 +718,7 @@ run_test! {intrinsics,size_of_val,stable} run_test! {intrinsics,transmute,stable} run_test! {intrinsics,trigonometry,stable} run_test! {intrinsics,type_id,stable} +run_test! {intrinsics,type_name,stable} run_test! {intrinsics,wrapping_ops,stable} run_test! {iter,fold,stable} run_test! {statics,thread_local,stable} diff --git a/src/lib.rs b/src/lib.rs index b74f3653..947873a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -320,10 +320,9 @@ impl ArchiveBuilderBuilder for RlibArchiveBuilder { &self, _sess: &Session, _lib_name: &str, - _dll_imports: &[rustc_session::cstore::DllImport], + _dll_imports: std::vec::Vec<(std::string::String, std::option::Option)>, _tmpdir: &Path, - _bool: bool, - ) -> PathBuf { + ) { unimplemented!("creating dll imports is not supported"); } } diff --git a/test/intrinsics/type_name.rs b/test/intrinsics/type_name.rs new file mode 100644 index 00000000..f1c231d1 --- /dev/null +++ b/test/intrinsics/type_name.rs @@ -0,0 +1,27 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params +)] +#![allow( + internal_features, + incomplete_features, + unused_variables, + dead_code, + unused_imports +)] +#![no_std] + +use core::intrinsics::type_name; + +include!("../common.rs"); + +fn main() { + test_eq!( + type_name::>(), + black_box("core::option::Option") + ); +}