From 8a3dd7fb5f9e2c3b6c8411e59ed7fa8d674c5a91 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 17 Jul 2024 17:01:59 +0200 Subject: [PATCH] add test for unions and repr(transparent) with ZST fields --- .../cmse-nonsecure-call/return-via-stack.rs | 19 ++++++++++ .../return-via-stack.stderr | 38 ++++++++++++++++++- .../cmse-nonsecure-call/via-registers.rs | 12 +++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs index c417dddac4f..2ea69327392 100644 --- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs +++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.rs @@ -39,3 +39,22 @@ pub fn test( f6(); //~ ERROR [E0798] f7(); //~ ERROR [E0798] } + +#[repr(C)] +pub union ReprCUnionU64 { + _unused: u64, +} + +#[repr(Rust)] +pub union ReprRustUnionU64 { + _unused: u64, +} + +#[no_mangle] +pub fn test_union( + f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64, //~ WARNING [improper_ctypes_definitions] + f2: extern "C-cmse-nonsecure-call" fn() -> ReprCUnionU64, +) { + f1(); //~ ERROR [E0798] + f2(); //~ ERROR [E0798] +} diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr index 6dea0cf68a0..99dc7ad4a9f 100644 --- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr +++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/return-via-stack.stderr @@ -15,6 +15,20 @@ LL | f7: extern "C-cmse-nonsecure-call" fn() -> i128, | = note: 128-bit integers don't currently have a known stable ABI +warning: `extern` fn uses type `ReprRustUnionU64`, which is not FFI-safe + --> $DIR/return-via-stack.rs:55:9 + | +LL | f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this union + = note: this union has unspecified layout +note: the type is defined here + --> $DIR/return-via-stack.rs:49:1 + | +LL | pub union ReprRustUnionU64 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers --> $DIR/return-via-stack.rs:34:5 | @@ -92,6 +106,28 @@ LL | f7(); | = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers -error: aborting due to 7 previous errors; 2 warnings emitted +error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers + --> $DIR/return-via-stack.rs:58:5 + | +LL | f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64, + | -- this function uses the `C-cmse-nonsecure-call` ABI +... +LL | f1(); + | ^^^^ but its return value doesn't fit in the available registers + | + = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers + +error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers + --> $DIR/return-via-stack.rs:59:5 + | +LL | f2: extern "C-cmse-nonsecure-call" fn() -> ReprCUnionU64, + | -- this function uses the `C-cmse-nonsecure-call` ABI +... +LL | f2(); + | ^^^^ but its return value doesn't fit in the available registers + | + = note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers + +error: aborting due to 9 previous errors; 3 warnings emitted For more information about this error, try `rustc --explain E0798`. diff --git a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs index 43768dd72f7..91aadd4fe1d 100644 --- a/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs +++ b/tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs @@ -10,7 +10,12 @@ pub trait Copy {} impl Copy for u32 {} #[repr(transparent)] -pub struct ReprTransparentStructU64(u64); +pub struct ReprTransparentStructU64 { + _marker1: (), + _marker2: (), + field: u64, + _marker3: (), +} #[repr(transparent)] pub enum ReprTransparentEnumU64 { @@ -36,7 +41,10 @@ pub fn params( f3(1, 2); f4(1); f5(1.0, 2.0, 3.0); - f6(ReprTransparentStructU64(1), U32Compound(2, 3)); + f6( + ReprTransparentStructU64 { _marker1: (), _marker2: (), field: 1, _marker3: () }, + U32Compound(2, 3), + ); f7([0xDEADBEEF; 4]); }