Skip to content

Commit

Permalink
rustc_trans: do not treat byval as using up registers.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 18, 2017
1 parent c398efc commit cba0c6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/librustc_trans/cabi_x86_64.rs
Expand Up @@ -229,12 +229,12 @@ pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType
};

if in_mem {
// `sret` / `byval` parameter thus one less integer register available
int_regs -= 1;

arg.make_indirect(ccx);
if is_arg {
arg.attrs.set(ArgAttribute::ByVal);
} else {
// `sret` parameter thus one less integer register available
int_regs -= 1;
}
} else {
// split into sized chunks passed individually
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-make/extern-fn-struct-passing-abi/test.c
Expand Up @@ -137,6 +137,21 @@ void byval_rect_with_float(int32_t a, int32_t b, float c, int32_t d,
assert(s.d == 556);
}

// System V x86_64 ABI:
// a, b, d, e, f should be byval pointer (on the stack)
// g passed via register (fixes #41375)
//
// Win64 ABI:
// a, b, d, e, f, g should be byval pointer
void byval_rect_with_many_huge(struct Huge a, struct Huge b, struct Huge c,
struct Huge d, struct Huge e, struct Huge f,
struct Rect g) {
assert(g.a == 123);
assert(g.b == 456);
assert(g.c == 789);
assert(g.d == 420);
}

// System V x86_64 & Win64 ABI:
// a, b should be in registers
// s should be split across 2 integer registers
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-make/extern-fn-struct-passing-abi/test.rs
Expand Up @@ -64,6 +64,8 @@ extern {

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

fn byval_rect_with_many_huge(a: Huge, b: Huge, c: Huge, d: Huge, e: Huge, f: Huge, g: Rect);

fn split_rect(a: i32, b: i32, s: Rect);

fn split_rect_floats(a: f32, b: f32, s: FloatRect);
Expand Down Expand Up @@ -95,6 +97,12 @@ fn main() {
byval_many_rect(1, 2, 3, 4, 5, 6, s);
byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u);
byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s);
byval_rect_with_many_huge(v, v, v, v, v, v, Rect {
a: 123,
b: 456,
c: 789,
d: 420
});
split_rect(1, 2, s);
split_rect_floats(1., 2., u);
split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s);
Expand Down

0 comments on commit cba0c6a

Please sign in to comment.