Rollup merge of #155522 - folkertdev:cmse-test-maybe-uninit, r=WaffleLapkin

cmse: test returning `MaybeUninit<T>`

tracking issue: https://github.com/rust-lang/rust/issues/81391
tracking issue: https://github.com/rust-lang/rust/issues/75835

Some tests from https://github.com/rust-lang/rust/pull/147697 that already work and are useful. Extracting them shrinks that (currently blocked) PR.

The code in `tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs` checks that `MaybeUninit<T>` is considered abi-compatible with `T`. The code in `tests/ui/cmse-nonsecure/cmse-nonsecure-entry/params-via-stack.rs` really only tests that no errors/warnings are emitted.

r? davidtwco
This commit is contained in:
Jonathan Brouwer
2026-04-25 00:08:10 +02:00
committed by GitHub
3 changed files with 53 additions and 4 deletions
+20
View File
@@ -27,6 +27,7 @@
decl_macro, decl_macro,
f16, f16,
f128, f128,
transparent_unions,
asm_experimental_arch, asm_experimental_arch,
unboxed_closures unboxed_closures
)] )]
@@ -127,6 +128,25 @@ pub struct ManuallyDrop<T: PointeeSized> {
} }
impl<T: Copy + PointeeSized> Copy for ManuallyDrop<T> {} impl<T: Copy + PointeeSized> Copy for ManuallyDrop<T> {}
#[lang = "maybe_uninit"]
#[repr(transparent)]
pub union MaybeUninit<T> {
uninit: (),
value: ManuallyDrop<T>,
}
impl<T: Copy + PointeeSized> Copy for MaybeUninit<T> {}
impl<T> MaybeUninit<T> {
pub const fn uninit() -> Self {
Self { uninit: () }
}
pub const fn new(value: T) -> Self {
Self { value: ManuallyDrop { value } }
}
}
#[repr(transparent)] #[repr(transparent)]
#[rustc_nonnull_optimization_guaranteed] #[rustc_nonnull_optimization_guaranteed]
pub struct NonNull<T: ?Sized> { pub struct NonNull<T: ?Sized> {
@@ -42,13 +42,13 @@ struct Test {
i128: extern "cmse-nonsecure-call" fn() -> i128, //~ ERROR [E0798] i128: extern "cmse-nonsecure-call" fn() -> i128, //~ ERROR [E0798]
} }
#[repr(C)] #[repr(Rust)]
pub union ReprCUnionU64 { pub union ReprRustUnionU64 {
_unused: u64, _unused: u64,
} }
#[repr(Rust)] #[repr(C)]
pub union ReprRustUnionU64 { pub union ReprCUnionU64 {
_unused: u64, _unused: u64,
} }
@@ -56,5 +56,11 @@ pub union ReprRustUnionU64 {
pub fn test_union( pub fn test_union(
f1: extern "cmse-nonsecure-call" fn() -> ReprRustUnionU64, //~ ERROR [E0798] f1: extern "cmse-nonsecure-call" fn() -> ReprRustUnionU64, //~ ERROR [E0798]
f2: extern "cmse-nonsecure-call" fn() -> ReprCUnionU64, //~ ERROR [E0798] f2: extern "cmse-nonsecure-call" fn() -> ReprCUnionU64, //~ ERROR [E0798]
// MaybeUninit is a transparent union, and hence MaybeUninit<u64> is abi-compatible with u64,
// and thus allowed as a return type.
f3: extern "cmse-nonsecure-call" fn() -> MaybeUninit<u32>,
f4: extern "cmse-nonsecure-call" fn() -> MaybeUninit<u64>,
f5: extern "cmse-nonsecure-call" fn() -> MaybeUninit<f64>,
) { ) {
} }
@@ -45,3 +45,26 @@ pub extern "cmse-nonsecure-entry" fn four(_: Four) {}
#[no_mangle] #[no_mangle]
pub extern "cmse-nonsecure-entry" fn five(_: Five) {} //~ ERROR [E0798] pub extern "cmse-nonsecure-entry" fn five(_: Five) {} //~ ERROR [E0798]
#[repr(Rust)]
pub union ReprRustUnionU64 {
_unused: u64,
}
#[repr(C)]
pub union ReprCUnionU64 {
_unused: u64,
}
#[no_mangle]
#[allow(improper_ctypes_definitions)]
pub extern "cmse-nonsecure-entry" fn union_rust(_: ReprRustUnionU64) {}
#[no_mangle]
pub extern "cmse-nonsecure-entry" fn union_c(_: ReprCUnionU64) {}
#[no_mangle]
pub extern "cmse-nonsecure-entry" fn maybe_uninit_32bit(_: MaybeUninit<u32>) {}
#[no_mangle]
pub extern "cmse-nonsecure-entry" fn maybe_uninit_64bit(_: MaybeUninit<f64>) {}