Skip to content

Commit 990233e

Browse files
committed
rustc: Allow calling native functions on the C stack that take generic arguments. They get turned into i8 pointers.
1 parent 276dfc6 commit 990233e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/comp/middle/trans.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,18 +4000,26 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
40004000
let llfn = f_res.val; bcx = f_res.bcx;
40014001

40024002
// Translate the callee.
4003-
let fn_ty = ty::expr_ty(bcx_tcx(bcx), f);
4003+
let { params: _, ty: fn_ty } = ty::expr_ty_params_and_ty(bcx_tcx(bcx), f);
40044004
let fn_arg_tys = ty::ty_fn_args(bcx_tcx(bcx), fn_ty);
40054005

40064006
// Translate arguments.
40074007
let (to_zero, to_revoke) = ([], []);
40084008
let llargs = vec::map2({ |ty_arg, arg|
40094009
let arg_ty = ty_arg.ty;
4010-
check type_has_static_size(ccx, arg_ty);
4011-
let llargty = type_of(ccx, f.span, arg_ty);
4010+
4011+
let static, llargty;
4012+
if check type_has_static_size(ccx, arg_ty) {
4013+
static = true;
4014+
llargty = type_of(ccx, f.span, arg_ty);
4015+
} else {
4016+
static = false;
4017+
llargty = T_ptr(T_i8());
4018+
}
4019+
40124020
let r = trans_arg_expr(bcx, ty_arg, llargty, to_zero, to_revoke, arg);
40134021
let llargval = r.val; bcx = r.bcx;
4014-
{ llval: llargval, llty: llargty }
4022+
{ llval: llargval, llty: llargty, static: static }
40154023
}, fn_arg_tys, args);
40164024

40174025
// Allocate the argument bundle.
@@ -4023,8 +4031,14 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
40234031

40244032
// Copy in arguments.
40254033
vec::eachi({ |llarg, i|
4026-
// FIXME: This load is unfortunate.
4027-
let llargval = Load(bcx, llarg.llval);
4034+
let llargval;
4035+
if llarg.static {
4036+
// FIXME: This load is unfortunate. It won't be necessary once we
4037+
// have reference types again.
4038+
llargval = Load(bcx, llarg.llval);
4039+
} else {
4040+
llargval = llarg.llval;
4041+
}
40284042
store_inbounds(bcx, llargval, llargbundle, [C_int(0), C_uint(i)]);
40294043
}, llargs);
40304044

0 commit comments

Comments
 (0)