Skip to content

Commit 855c99e

Browse files
committed
Some tests for passing and returning structures by value on x64. Close #1402. Close #1970.
1 parent f5087aa commit 855c99e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/rt/rust_builtin.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,43 @@ rand_free(randctx *rctx) {
200200
task->free(rctx);
201201
}
202202

203+
204+
/* Debug helpers strictly to verify ABI conformance.
205+
*
206+
* FIXME: move these into a testcase when the testsuite
207+
* understands how to have explicit C files included.
208+
*/
209+
210+
struct quad {
211+
uint64_t a;
212+
uint64_t b;
213+
uint64_t c;
214+
uint64_t d;
215+
};
216+
217+
struct floats {
218+
double a;
219+
uint8_t b;
220+
double c;
221+
};
222+
223+
extern "C" quad
224+
debug_abi_1(quad q) {
225+
quad qq = { q.c + 1,
226+
q.d - 1,
227+
q.a + 1,
228+
q.b - 1 };
229+
return qq;
230+
}
231+
232+
extern "C" floats
233+
debug_abi_2(floats f) {
234+
floats ff = { f.c + 1.0,
235+
0xff,
236+
f.a - 1.0 };
237+
return ff;
238+
}
239+
203240
/* Debug builtins for std::dbg. */
204241

205242
static void

src/rt/rustrt.def.in

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ debug_ptrcast
77
debug_tag
88
debug_tydesc
99
debug_get_stk_seg
10+
debug_abi_1
11+
debug_abi_2
1012
get_port_id
1113
get_task_id
1214
get_time

src/test/run-pass/struct-return.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
type quad = { a: u64, b: u64, c: u64, d: u64 };
3+
type floats = { a: f64, b: u8, c: f64 };
4+
5+
#[nolink]
6+
native mod rustrt {
7+
fn debug_abi_1(++q: quad) -> quad;
8+
fn debug_abi_2(++f: floats) -> floats;
9+
}
10+
11+
fn main() {
12+
13+
// First check
14+
let q = { a: 0xaaaa_aaaa_aaaa_aaaa_u64,
15+
b: 0xbbbb_bbbb_bbbb_bbbb_u64,
16+
c: 0xcccc_cccc_cccc_cccc_u64,
17+
d: 0xdddd_dddd_dddd_dddd_u64 };
18+
let qq = rustrt::debug_abi_1(q);
19+
#error("a: %x", qq.a as uint);
20+
#error("b: %x", qq.b as uint);
21+
#error("c: %x", qq.c as uint);
22+
#error("d: %x", qq.d as uint);
23+
assert qq.a == q.c + 1u64;
24+
assert qq.b == q.d - 1u64;
25+
assert qq.c == q.a + 1u64;
26+
assert qq.d == q.b - 1u64;
27+
28+
// Second check
29+
let f = { a: 1.234567890e-15_f64,
30+
b: 0b_1010_1010_u8,
31+
c: 1.0987654321e-15_f64 };
32+
let ff = rustrt::debug_abi_2(f);
33+
#error("a: %f", ff.a as float);
34+
#error("b: %u", ff.b as uint);
35+
#error("c: %f", ff.c as float);
36+
assert ff.a == f.c + 1.0;
37+
assert ff.b == 0xff_u8;
38+
assert ff.c == f.a - 1.0;
39+
}

0 commit comments

Comments
 (0)