Skip to content

Commit 39d8424

Browse files
Rollup merge of rust-lang#155522 - folkertdev:cmse-test-maybe-uninit, r=WaffleLapkin
cmse: test returning `MaybeUninit<T>` tracking issue: rust-lang#81391 tracking issue: rust-lang#75835 Some tests from rust-lang#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
2 parents 6d6b99e + 640c4b4 commit 39d8424

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

tests/auxiliary/minicore.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
decl_macro,
2828
f16,
2929
f128,
30+
transparent_unions,
3031
asm_experimental_arch,
3132
unboxed_closures
3233
)]
@@ -127,6 +128,25 @@ pub struct ManuallyDrop<T: PointeeSized> {
127128
}
128129
impl<T: Copy + PointeeSized> Copy for ManuallyDrop<T> {}
129130

131+
#[lang = "maybe_uninit"]
132+
#[repr(transparent)]
133+
pub union MaybeUninit<T> {
134+
uninit: (),
135+
value: ManuallyDrop<T>,
136+
}
137+
138+
impl<T: Copy + PointeeSized> Copy for MaybeUninit<T> {}
139+
140+
impl<T> MaybeUninit<T> {
141+
pub const fn uninit() -> Self {
142+
Self { uninit: () }
143+
}
144+
145+
pub const fn new(value: T) -> Self {
146+
Self { value: ManuallyDrop { value } }
147+
}
148+
}
149+
130150
#[repr(transparent)]
131151
#[rustc_nonnull_optimization_guaranteed]
132152
pub struct NonNull<T: ?Sized> {

tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ struct Test {
4242
i128: extern "cmse-nonsecure-call" fn() -> i128, //~ ERROR [E0798]
4343
}
4444

45-
#[repr(C)]
46-
pub union ReprCUnionU64 {
45+
#[repr(Rust)]
46+
pub union ReprRustUnionU64 {
4747
_unused: u64,
4848
}
4949

50-
#[repr(Rust)]
51-
pub union ReprRustUnionU64 {
50+
#[repr(C)]
51+
pub union ReprCUnionU64 {
5252
_unused: u64,
5353
}
5454

5555
#[no_mangle]
5656
pub fn test_union(
5757
f1: extern "cmse-nonsecure-call" fn() -> ReprRustUnionU64, //~ ERROR [E0798]
5858
f2: extern "cmse-nonsecure-call" fn() -> ReprCUnionU64, //~ ERROR [E0798]
59+
60+
// MaybeUninit is a transparent union, and hence MaybeUninit<u64> is abi-compatible with u64,
61+
// and thus allowed as a return type.
62+
f3: extern "cmse-nonsecure-call" fn() -> MaybeUninit<u32>,
63+
f4: extern "cmse-nonsecure-call" fn() -> MaybeUninit<u64>,
64+
f5: extern "cmse-nonsecure-call" fn() -> MaybeUninit<f64>,
5965
) {
6066
}

tests/ui/cmse-nonsecure/cmse-nonsecure-entry/params-via-stack.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,26 @@ pub extern "cmse-nonsecure-entry" fn four(_: Four) {}
4545

4646
#[no_mangle]
4747
pub extern "cmse-nonsecure-entry" fn five(_: Five) {} //~ ERROR [E0798]
48+
49+
#[repr(Rust)]
50+
pub union ReprRustUnionU64 {
51+
_unused: u64,
52+
}
53+
54+
#[repr(C)]
55+
pub union ReprCUnionU64 {
56+
_unused: u64,
57+
}
58+
59+
#[no_mangle]
60+
#[allow(improper_ctypes_definitions)]
61+
pub extern "cmse-nonsecure-entry" fn union_rust(_: ReprRustUnionU64) {}
62+
63+
#[no_mangle]
64+
pub extern "cmse-nonsecure-entry" fn union_c(_: ReprCUnionU64) {}
65+
66+
#[no_mangle]
67+
pub extern "cmse-nonsecure-entry" fn maybe_uninit_32bit(_: MaybeUninit<u32>) {}
68+
69+
#[no_mangle]
70+
pub extern "cmse-nonsecure-entry" fn maybe_uninit_64bit(_: MaybeUninit<f64>) {}

0 commit comments

Comments
 (0)