Skip to content

Commit 4498cd6

Browse files
extend extern tests to include FiveU16s
As described in the code, this extends just beyond a 64bit reg, but isn't a round number, so it triggers some edge cases in the cast ABI.
1 parent 766bdce commit 4498cd6

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

tests/auxiliary/rust_test_helpers.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u) {
118118
return u;
119119
}
120120

121+
struct FiveU16s {
122+
uint16_t one;
123+
uint16_t two;
124+
uint16_t three;
125+
uint16_t four;
126+
uint16_t five;
127+
};
128+
129+
struct FiveU16s
130+
rust_dbg_extern_return_FiveU16s() {
131+
struct FiveU16s s;
132+
s.one = 10;
133+
s.two = 20;
134+
s.three = 30;
135+
s.four = 40;
136+
s.five = 50;
137+
return s;
138+
}
139+
140+
struct FiveU16s
141+
rust_dbg_extern_identity_FiveU16s(struct FiveU16s u) {
142+
return u;
143+
}
144+
121145
struct ManyInts {
122146
int8_t arg1;
123147
int16_t arg2;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ run-pass
2+
#![allow(improper_ctypes)]
3+
4+
// Test a foreign function that accepts and returns a struct by value.
5+
6+
// FiveU16s in particular is interesting because it is larger than a single 64 bit or 32 bit
7+
// register, which are used as cast destinations on some targets, but does not evenly divide those
8+
// sizes, causing there to be padding in the last element.
9+
10+
#[derive(Copy, Clone, PartialEq, Debug)]
11+
pub struct FiveU16s {
12+
one: u16,
13+
two: u16,
14+
three: u16,
15+
four: u16,
16+
five: u16,
17+
}
18+
19+
#[link(name = "rust_test_helpers", kind = "static")]
20+
extern "C" {
21+
pub fn rust_dbg_extern_identity_FiveU16s(v: FiveU16s) -> FiveU16s;
22+
}
23+
24+
pub fn main() {
25+
unsafe {
26+
let x = FiveU16s { one: 22, two: 23, three: 24, four: 25, five: 26 };
27+
let y = rust_dbg_extern_identity_FiveU16s(x);
28+
assert_eq!(x, y);
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ run-pass
2+
#![allow(improper_ctypes)]
3+
4+
pub struct FiveU16s {
5+
one: u16,
6+
two: u16,
7+
three: u16,
8+
four: u16,
9+
five: u16,
10+
}
11+
12+
#[link(name = "rust_test_helpers", kind = "static")]
13+
extern "C" {
14+
pub fn rust_dbg_extern_return_FiveU16s() -> FiveU16s;
15+
}
16+
17+
pub fn main() {
18+
unsafe {
19+
let y = rust_dbg_extern_return_FiveU16s();
20+
assert_eq!(y.one, 10);
21+
assert_eq!(y.two, 20);
22+
assert_eq!(y.three, 30);
23+
assert_eq!(y.four, 40);
24+
assert_eq!(y.five, 50);
25+
}
26+
}

0 commit comments

Comments
 (0)