Skip to content

Commit 7b44392

Browse files
eddybalexcrichton
authored andcommitted
rustc_trans: do not treat byval as using up registers.
1 parent 275549b commit 7b44392

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/librustc_trans/cabi_x86_64.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,7 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
375375
let in_mem = cls.is_pass_byval() ||
376376
int_regs < needed_int ||
377377
sse_regs < needed_sse;
378-
if in_mem {
379-
// `byval` parameter thus one less integer register available
380-
int_regs -= 1;
381-
} else {
378+
if !in_mem {
382379
// split into sized chunks passed individually
383380
int_regs -= needed_int;
384381
sse_regs -= needed_sse;

src/test/run-make/extern-fn-struct-passing-abi/test.c

+15
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ void byval_rect_with_float(int32_t a, int32_t b, float c, int32_t d,
132132
assert(s.d == 556);
133133
}
134134

135+
// System V x86_64 ABI:
136+
// a, b, d, e, f should be byval pointer (on the stack)
137+
// g passed via register (fixes #41375)
138+
//
139+
// Win64 ABI:
140+
// a, b, d, e, f, g should be byval pointer
141+
void byval_rect_with_many_huge(struct Huge a, struct Huge b, struct Huge c,
142+
struct Huge d, struct Huge e, struct Huge f,
143+
struct Rect g) {
144+
assert(g.a == 123);
145+
assert(g.b == 456);
146+
assert(g.c == 789);
147+
assert(g.d == 420);
148+
}
149+
135150
// System V x86_64 & Win64 ABI:
136151
// a, b should be in registers
137152
// s should be split across 2 integer registers

src/test/run-make/extern-fn-struct-passing-abi/test.rs

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ extern {
5757

5858
fn byval_rect_with_float(a: i32, b: i32, c: f32, d: i32, e: i32, f: i32, s: Rect);
5959

60+
fn byval_rect_with_many_huge(a: Huge, b: Huge, c: Huge, d: Huge, e: Huge, f: Huge, g: Rect);
61+
6062
fn split_rect(a: i32, b: i32, s: Rect);
6163

6264
fn split_rect_floats(a: f32, b: f32, s: FloatRect);
@@ -85,6 +87,12 @@ fn main() {
8587
byval_many_rect(1, 2, 3, 4, 5, 6, s);
8688
byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u);
8789
byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s);
90+
byval_rect_with_many_huge(v, v, v, v, v, v, Rect {
91+
a: 123,
92+
b: 456,
93+
c: 789,
94+
d: 420
95+
});
8896
split_rect(1, 2, s);
8997
split_rect_floats(1., 2., u);
9098
split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s);

0 commit comments

Comments
 (0)