Skip to content

Commit 8703c80

Browse files
committed
FIx native wrapper generation to handle more arg types.
1 parent 361ee5a commit 8703c80

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,15 +6148,15 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
61486148
auto arg_n = 3u;
61496149
auto pass_task;
61506150

6151-
auto lltaskptr = bcx.build.PtrToInt(fcx.lltaskptr, T_int());
6151+
auto lltaskptr = vp2i(bcx, fcx.lltaskptr);
61526152
alt (abi) {
61536153
case (ast.native_abi_rust) {
61546154
pass_task = true;
61556155
call_args += vec(lltaskptr);
61566156
for each (uint i in _uint.range(0u, num_ty_param)) {
61576157
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
61586158
check (llarg as int != 0);
6159-
call_args += vec(bcx.build.PointerCast(llarg, T_i32()));
6159+
call_args += vec(vp2i(bcx, llarg));
61606160
arg_n += 1u;
61616161
}
61626162
}
@@ -6169,6 +6169,26 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
61696169
}
61706170
}
61716171

6172+
fn push_arg(@block_ctxt cx,
6173+
&mutable vec[ValueRef] args,
6174+
ValueRef v,
6175+
@ty.t t) {
6176+
if (ty.type_is_integral(t)) {
6177+
auto lldsttype = T_int();
6178+
auto llsrctype = type_of(cx.fcx.ccx, t);
6179+
if (llvm.LLVMGetIntTypeWidth(lldsttype) >
6180+
llvm.LLVMGetIntTypeWidth(llsrctype)) {
6181+
args += vec(cx.build.ZExtOrBitCast(v, T_int()));
6182+
} else {
6183+
args += vec(cx.build.TruncOrBitCast(v, T_int()));
6184+
}
6185+
} else if (ty.type_is_fp(t)) {
6186+
args += vec(cx.build.FPToSI(v, T_int()));
6187+
} else {
6188+
args += vec(vp2i(cx, v));
6189+
}
6190+
}
6191+
61726192
auto r;
61736193
auto rptr;
61746194
auto args = ty.ty_fn_args(fn_type);
@@ -6192,7 +6212,7 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
61926212
for (ty.arg arg in args) {
61936213
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
61946214
check (llarg as int != 0);
6195-
call_args += vec(bcx.build.PointerCast(llarg, T_i32()));
6215+
push_arg(bcx, call_args, llarg, arg.ty);
61966216
arg_n += 1u;
61976217
}
61986218

0 commit comments

Comments
 (0)