diff options
| author | bors <bors@rust-lang.org> | 2022-12-14 19:14:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-14 19:14:39 +0000 |
| commit | b70baa4f922a1809d79caeaeb902800c3be283b9 (patch) | |
| tree | 5a0604d612b44709a6ad083a1d975ae29b526252 /src/test/codegen | |
| parent | fbf8b937b44d39ba03835b82ed7ea443321eb7c7 (diff) | |
| parent | 3069bc0c14a79721bb73a4174620cee2aa27382d (diff) | |
| download | rust-b70baa4f922a1809d79caeaeb902800c3be283b9.tar.gz rust-b70baa4f922a1809d79caeaeb902800c3be283b9.zip | |
Auto merge of #105703 - matthiaskrgr:rollup-tfpeam2, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #105399 (Use more LFS functions.) - #105578 (Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR)) - #105598 (explain mem::forget(env_lock) in fork/exec) - #105624 (Fix unsoundness in bootstrap cache code) - #105630 (Add a test for #92481) - #105684 (Improve rustdoc markdown variable naming) - #105697 (Remove fee1-dead from reviewers) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/avr/avr-func-addrspace.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/test/codegen/avr/avr-func-addrspace.rs b/src/test/codegen/avr/avr-func-addrspace.rs index cbbcfad3ef4..e9740e30da4 100644 --- a/src/test/codegen/avr/avr-func-addrspace.rs +++ b/src/test/codegen/avr/avr-func-addrspace.rs @@ -9,7 +9,7 @@ // It also validates that functions can be called through function pointers // through traits. -#![feature(no_core, lang_items, unboxed_closures, arbitrary_self_types)] +#![feature(no_core, lang_items, intrinsics, unboxed_closures, arbitrary_self_types)] #![crate_type = "lib"] #![no_core] @@ -49,6 +49,10 @@ pub trait Fn<Args: Tuple>: FnOnce<Args> { extern "rust-call" fn call(&self, args: Args) -> Self::Output; } +extern "rust-intrinsic" { + pub fn transmute<Src, Dst>(src: Src) -> Dst; +} + pub static mut STORAGE_FOO: fn(&usize, &mut u32) -> Result<(), ()> = arbitrary_black_box; pub static mut STORAGE_BAR: u32 = 12; @@ -87,3 +91,21 @@ pub extern "C" fn test() { STORAGE_FOO(&1, &mut buf); } } + +// Validate that we can codegen transmutes between data ptrs and fn ptrs. + +// CHECK: define{{.+}}{{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}} @transmute_data_ptr_to_fn({{\{\}\*|ptr}}{{.*}} %x) +#[no_mangle] +pub unsafe fn transmute_data_ptr_to_fn(x: *const ()) -> fn() { + // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), + // as long as it doesn't cause a verifier error by using `bitcast`. + transmute(x) +} + +// CHECK: define{{.+}}{{\{\}\*|ptr}} @transmute_fn_ptr_to_data({{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}}{{.*}} %x) +#[no_mangle] +pub unsafe fn transmute_fn_ptr_to_data(x: fn()) -> *const () { + // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), + // as long as it doesn't cause a verifier error by using `bitcast`. + transmute(x) +} |
