Skip to content

Commit 82f08ea

Browse files
committed
trans: Use an isize to count the number of registers so we don't underflow for fn's with > 7 args in debug builds.
1 parent be91042 commit 82f08ea

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/librustc_trans/trans/cabi_x86_64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
411411
}
412412

413413
let mut int_regs = 6; // RDI, RSI, RDX, RCX, R8, R9
414-
let mut sse_regs = 8;
414+
let mut sse_regs = 8; // XMM0-7
415415

416416
let ret_ty = if ret_def {
417417
x86_64_ty(ccx, rty, |cls| {
@@ -430,8 +430,8 @@ pub fn compute_abi_info(ccx: &CrateContext,
430430
let mut arg_tys = Vec::new();
431431
for t in atys {
432432
let ty = x86_64_ty(ccx, *t, |cls| {
433-
let needed_int = cls.iter().filter(|&&c| c == Int).count();
434-
let needed_sse = cls.iter().filter(|c| c.is_sse()).count();
433+
let needed_int = cls.iter().filter(|&&c| c == Int).count() as isize;
434+
let needed_sse = cls.iter().filter(|c| c.is_sse()).count() as isize;
435435
let in_mem = cls.is_pass_byval() ||
436436
int_regs < needed_int ||
437437
sse_regs < needed_sse;

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

+22
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ void byval_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, struct Re
5858
assert(s.d == 556);
5959
}
6060

61+
// System V x86_64 ABI:
62+
// a, b, c, d, e, f should be in registers
63+
// s should be byval pointer on the stack
64+
//
65+
// Win64 ABI:
66+
// a, b, c, d should be in registers
67+
// e, f should be on the stack
68+
// s should be byval pointer on the stack
69+
void byval_many_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
70+
int32_t f, struct Rect s) {
71+
assert(a == 1);
72+
assert(b == 2);
73+
assert(c == 3);
74+
assert(d == 4);
75+
assert(e == 5);
76+
assert(f == 6);
77+
assert(s.a == 553);
78+
assert(s.b == 554);
79+
assert(s.c == 555);
80+
assert(s.d == 556);
81+
}
82+
6183
// System V x86_64 ABI:
6284
// a, b, c, d, e, f, g should be in sse registers
6385
// s should be split across 2 registers

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

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct Huge {
5050
extern {
5151
fn byval_rect(a: i32, b: i32, c: i32, d: i32, e: i32, s: Rect);
5252

53+
fn byval_many_rect(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, s: Rect);
54+
5355
fn byval_rect_floats(a: f32, b: f32, c: f64, d: f32, e: f32,
5456
f: f32, g: f64, s: Rect, t: FloatRect);
5557

@@ -80,6 +82,7 @@ fn main() {
8082

8183
unsafe {
8284
byval_rect(1, 2, 3, 4, 5, s);
85+
byval_many_rect(1, 2, 3, 4, 5, 6, s);
8386
byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u);
8487
byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s);
8588
split_rect(1, 2, s);

0 commit comments

Comments
 (0)