Skip to content

Commit 8a3dd7f

Browse files
committed
add test for unions and repr(transparent) with ZST fields
1 parent 5f0f690 commit 8a3dd7f

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ pub fn test(
3939
f6(); //~ ERROR [E0798]
4040
f7(); //~ ERROR [E0798]
4141
}
42+
43+
#[repr(C)]
44+
pub union ReprCUnionU64 {
45+
_unused: u64,
46+
}
47+
48+
#[repr(Rust)]
49+
pub union ReprRustUnionU64 {
50+
_unused: u64,
51+
}
52+
53+
#[no_mangle]
54+
pub fn test_union(
55+
f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64, //~ WARNING [improper_ctypes_definitions]
56+
f2: extern "C-cmse-nonsecure-call" fn() -> ReprCUnionU64,
57+
) {
58+
f1(); //~ ERROR [E0798]
59+
f2(); //~ ERROR [E0798]
60+
}

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

+37-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ LL | f7: extern "C-cmse-nonsecure-call" fn() -> i128,
1515
|
1616
= note: 128-bit integers don't currently have a known stable ABI
1717

18+
warning: `extern` fn uses type `ReprRustUnionU64`, which is not FFI-safe
19+
--> $DIR/return-via-stack.rs:55:9
20+
|
21+
LL | f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64,
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
23+
|
24+
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this union
25+
= note: this union has unspecified layout
26+
note: the type is defined here
27+
--> $DIR/return-via-stack.rs:49:1
28+
|
29+
LL | pub union ReprRustUnionU64 {
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
1832
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
1933
--> $DIR/return-via-stack.rs:34:5
2034
|
@@ -92,6 +106,28 @@ LL | f7();
92106
|
93107
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
94108

95-
error: aborting due to 7 previous errors; 2 warnings emitted
109+
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
110+
--> $DIR/return-via-stack.rs:58:5
111+
|
112+
LL | f1: extern "C-cmse-nonsecure-call" fn() -> ReprRustUnionU64,
113+
| -- this function uses the `C-cmse-nonsecure-call` ABI
114+
...
115+
LL | f1();
116+
| ^^^^ but its return value doesn't fit in the available registers
117+
|
118+
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
119+
120+
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
121+
--> $DIR/return-via-stack.rs:59:5
122+
|
123+
LL | f2: extern "C-cmse-nonsecure-call" fn() -> ReprCUnionU64,
124+
| -- this function uses the `C-cmse-nonsecure-call` ABI
125+
...
126+
LL | f2();
127+
| ^^^^ but its return value doesn't fit in the available registers
128+
|
129+
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
130+
131+
error: aborting due to 9 previous errors; 3 warnings emitted
96132

97133
For more information about this error, try `rustc --explain E0798`.

tests/ui/cmse-nonsecure/cmse-nonsecure-call/via-registers.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ pub trait Copy {}
1010
impl Copy for u32 {}
1111

1212
#[repr(transparent)]
13-
pub struct ReprTransparentStructU64(u64);
13+
pub struct ReprTransparentStructU64 {
14+
_marker1: (),
15+
_marker2: (),
16+
field: u64,
17+
_marker3: (),
18+
}
1419

1520
#[repr(transparent)]
1621
pub enum ReprTransparentEnumU64 {
@@ -36,7 +41,10 @@ pub fn params(
3641
f3(1, 2);
3742
f4(1);
3843
f5(1.0, 2.0, 3.0);
39-
f6(ReprTransparentStructU64(1), U32Compound(2, 3));
44+
f6(
45+
ReprTransparentStructU64 { _marker1: (), _marker2: (), field: 1, _marker3: () },
46+
U32Compound(2, 3),
47+
);
4048
f7([0xDEADBEEF; 4]);
4149
}
4250

0 commit comments

Comments
 (0)